#Boa:Frame:Frame1
# -*- coding: gbk -*-

import wx
import wx.lib.dialogs
#from wx.lib.pdfwin import PDFWindow
import re
import os
import sys
import glob
import shutil
import time
import zipfile
import tarfile
import string


from Configure_ver00 import Config
from Data2Bhtc_ver01 import NewUiData2BHTC
from BHTC2CustData_ver00  import BHTC2CustData
#from renamefile import Rename
from WaferMapView_ver00 import MyWaferMapFrame
from ConfigDevice_ver00 import NewConfigDevice

ProjectPath=os.getcwd()
ConfigFile="config_NewUi"
HelpFile="NewDataProcessManual.pdf"
TestDataPath=""
DeviceInData=[]
LotNumInData=""
WaferIDInData="01;"
TestDataDir=""
SortTypesInData="Sort1"
VersionInData={}

DeviceInMapData=[]
VersionInMapData={}
LotNumInMapData=""
SortTypesInMapData=["Sort1"]

DeviceInWaferMap=[]
VersionInWaferMap={}
LotNumInWaferMap=""
WaferIdInWaferMap=""
SortTypesInWaferMap="Sort1"

DeviceInConfigration=""
SortTypesInConfigration="Sort1"
VersionInConfigration=""
PathInConfigration=""
TestDataFileInConfigration="01;"
DeviceConfigInformation=""

DeviceInModifyPassWafer=[]
VersionInModifyPassWafer=""
LotNumInModifyPassWafer=""
WaferIDInModifyPassWafer="01;"
SortTypesInModifyPassWafer="Sort1"

DeviceInConfirmPassLot=[]
VersionInConfirmPassLot=""
LotNumInConfirmPassLot=""
RespInConfirmPassLot=""

FlagDevice=False
FlagLotNum=False
#FlagSortType=False
FlagWaferId=False
FlagVersion=False

FlagDeviceInMap=False
FlagLotNumInMap=False
FlagVersionInMap=False

FlagDeviceInWaferMap=False
FlagLotNumInWaferMap=False
FlagVersionInWaferMap=False
FlagWaferIdInWaferMap=False
IndexInWaferMap=0

FlagDeviceInConfigration=False
FlagPathInConfigration=False
FlagVersionInConfigration=False
FlagTestDataInConfigration=False

FlagDeviceInModifyPassWafer=False
FlagLotNumInModifyPassWafer=False
FlagWaferIdInModifyPassWafer=False


FlagDeviceInConfirmPassLot=False
FlagVersionInConfirmPassLot=False
FlagRespInConfirmPassLot=False
FlagLotNumInConfirmPassLot=False



wildcard = "Data File (*.data)|*.data|"     \
            "Python source (*.py)|*.py|"     \
            "Compiled Python (*.pyc)|*.pyc|" \
            "SPAM files (*.spam)|*.spam|"    \
            "Egg file (*.egg)|*.egg|"        \
            "All files (*.*)|*.*"


def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1CONFIGDEVICESTATICTTEXTINCONFIGRATION, 
 wxID_FRAME1CONFIGINDATA, wxID_FRAME1CONFIGRATION, 
 wxID_FRAME1CONFIGSTATICBOXINMAPDATA, wxID_FRAME1CONFIGSTATICBOXINWAFERMAP, 
 wxID_FRAME1CONFIRMPASSLOT, wxID_FRAME1DELETEBUTTONINMODIFYPASSWAFER, 
 wxID_FRAME1DEVICECHOICEINCONFIRMPASSLOT, wxID_FRAME1DEVICECHOICEINDATA, 
 wxID_FRAME1DEVICECHOICEINMAPDATA, wxID_FRAME1DEVICECHOICEINWAFERMAP, 
 wxID_FRAME1DEVICENAMECHOICEINMODIFYPASSWAFER, 
 wxID_FRAME1DEVICENAMESTATICTEXTINCONFIGRATION, 
 wxID_FRAME1DEVICENAMESTATICTEXTINMODIFYPASSWAFER, 
 wxID_FRAME1DEVICENAMETEXTCTRLINCONFIGRATION, 
 wxID_FRAME1DEVICESTATICTEXTINCONFIRMPASSLOT, 
 wxID_FRAME1DEVICESTATICTEXTINDATA, wxID_FRAME1DEVICESTATICTEXTINMAPDATA, 
 wxID_FRAME1DEVICESTATICTEXTINWAFERMAP, 
 wxID_FRAME1DEVICEVERSIONSTATICTEXTINCOFIGRATION, 
 wxID_FRAME1DEVICEVERSIONTEXTCTRLINCONFIGRATION, 
 wxID_FRAME1EXITBUTTONINCONFIGRATION, wxID_FRAME1EXITBUTTONINCONFIRMPASSLOT, 
 wxID_FRAME1EXITBUTTONINDATA, wxID_FRAME1EXITBUTTONINMAPDATA, 
 wxID_FRAME1EXITBUTTONINMODIFYPASSWAFER, wxID_FRAME1EXITBUTTONINWAFERMAP, 
 wxID_FRAME1GAUGEINDATA, wxID_FRAME1HEADSTATICTEXTINCONFIRMPASSLOT, 
 wxID_FRAME1HEADSTATICTEXTINMODIFYPASSWAFER, 
 wxID_FRAME1HELPFILESTATICBOXINCONFIGRATION, 
 wxID_FRAME1HELPFILESTATICTEXTINCONFIGRATION, 
 wxID_FRAME1LOTNOBUTTONINCONFIRMPASSLOT, wxID_FRAME1LOTNOBUTTONINDATA, 
 wxID_FRAME1LOTNOBUTTONINMAPDATA, wxID_FRAME1LOTNOBUTTONINMODIFYPASSWAFER, 
 wxID_FRAME1LOTNOBUTTONINWAFERMAP, wxID_FRAME1LOTNOSTATICTEXTINCONFIRMPASSLOT, 
 wxID_FRAME1LOTNOSTATICTEXTINMAPDATA, 
 wxID_FRAME1LOTNOSTATICTEXTINMODIFYPASSWAFER, 
 wxID_FRAME1LOTNOTEXTCTRLINCONFIRMPASSLOT, wxID_FRAME1LOTNOTEXTCTRLINDATA, 
 wxID_FRAME1LOTNOTEXTCTRLINMAPDATA, wxID_FRAME1LOTNOTEXTCTRLINMODIFYPASSWAFER, 
 wxID_FRAME1LOTNUMSTATICTEXTINDATA, wxID_FRAME1LOTNUMSTATICTEXTINWAFERMAP, 
 wxID_FRAME1LOTNUMTEXTCTRLINWAFERMAP, wxID_FRAME1MANUALCONVERTTOOL, 
 wxID_FRAME1MAPDATATOOL, wxID_FRAME1NEXTBUTTONINWAFERMAP, 
 wxID_FRAME1NOTE1STATICTEXTINCONFIRMPASSLOT, 
 wxID_FRAME1NOTE2STATICTEXTINCONFIRMPASSLOT, 
 wxID_FRAME1NOTE3STATICTEXTINCONFIRMPASSLOT, wxID_FRAME1NOTEBOOK1, 
 wxID_FRAME1NOTESTATICBOXINCONFIRMPASSLOT, 
 wxID_FRAME1OPENHELPFILEBUTTONINCONFIGRATION, wxID_FRAME1PANEL1, 
 wxID_FRAME1PATHSTATICTEXTINCONFIGRATION, 
 wxID_FRAME1PATHTEXTCTRLINCONFIGRATION, wxID_FRAME1PREBUTTONINWAFERMAP, 
 wxID_FRAME1RECONFBUTTONINCONFIRMPASSLOT, 
 wxID_FRAME1RECONFBUTTONINMODIFYPASSWAFER, 
 wxID_FRAME1RECONFIGBUTTONINCONFIGRATION, wxID_FRAME1RECONFIGBUTTONINDATA, 
 wxID_FRAME1RESPCHOICEINCONFIRMPASSLOT, 
 wxID_FRAME1RESPSTATICTEXTINCONFIRMPASSLOT, 
 wxID_FRAME1SORTTYPERADIOBOXINCONFIGRATION, wxID_FRAME1SORTTYPERADIOBOXINDATA, 
 wxID_FRAME1SORTTYPERADIOBOXINMAPDATA, wxID_FRAME1SORTTYPERADIOBOXINWAFERMAP, 
 wxID_FRAME1SORTTYPESRADIOBOXINMODIFYPASSWAFER, 
 wxID_FRAME1STARTBUTTONINCONFIGRATION, wxID_FRAME1STARTBUTTONINCONFIRMPASSLOT, 
 wxID_FRAME1STARTBUTTONINDATA, wxID_FRAME1STARTBUTTONINMAPDATA, 
 wxID_FRAME1STARTBUTTONINWAFERMAP, 
 wxID_FRAME1TESTDATAFILEBUTTONINCONFIGRATION, 
 wxID_FRAME1TESTDATAFILESTATICTEXTINCONFIGRATION, 
 wxID_FRAME1TESTDATAFILETEXTCTRLINCONFIGRATION, 
 wxID_FRAME1TESTDATAPATHBUTTONINCONFIGRATION, 
 wxID_FRAME1TESTDATAPATHSATICBOXINCONFIGRATION, 
 wxID_FRAME1TESTDATAPATHSTATICTEXTINCONFIGRATION, 
 wxID_FRAME1TESTDATAPATHTEXTCTRLINCOFIGRATION, wxID_FRAME1TITILEINMAPDATA, 
 wxID_FRAME1TITLESTATICTEXTINDATA, wxID_FRAME1TITLESTATICTEXTINWAFERMAP, 
 wxID_FRAME1VERSIONCHOICEINCONFIRMPASSLOT, wxID_FRAME1VERSIONCHOICEINDATA, 
 wxID_FRAME1VERSIONCHOICEINMAPDATA, wxID_FRAME1VERSIONCHOICEINMODIFYPASSWAFER, 
 wxID_FRAME1VERSIONCHOICEINWAFERMAP, 
 wxID_FRAME1VERSIONSTATICTEXTINCONFIRMPASSLOT, 
 wxID_FRAME1VERSIONSTATICTEXTINDATA, wxID_FRAME1VERSIONSTATICTEXTINMAPDATA, 
 wxID_FRAME1VERSIONSTATICTEXTINMODIFYPASSWAFER, 
 wxID_FRAME1VERSIONSTATICTEXTINWAFERMAP, wxID_FRAME1VIEWBUTTONINMAPDATA, 
 wxID_FRAME1WAFERIDSTATICTEXTINMODIFYPASSWAFER, 
 wxID_FRAME1WAFERIDTEXTCTRLINMODIFYPASSWAFER, wxID_FRAME1WAFERMAPVIEW, 
 wxID_FRAME1WAFERNOSTATICTEXTINDATA, wxID_FRAME1WAFERNOSTATICTEXTINWAFERMAP, 
 wxID_FRAME1WAFERNOTEXTCTRLINDATA, wxID_FRAME1WAFERNOTEXTCTRLINWAFERMAP, 
] = [wx.NewId() for _init_ctrls in range(105)]

class Frame1(wx.Frame):
    def _init_coll_notebook1_Pages(self, parent):
        # generated method, don't edit

        parent.AddPage(imageId=-1, page=self.ManualConvertTool, select=True,
              text=u'\u6570\u636e\u5904\u7406')
        parent.AddPage(imageId=-1, page=self.WaferMapView, select=False,
              text=u'WaferMap')
        parent.AddPage(imageId=-1, page=self.MapDataTool, select=False,
              text=u'MapData')
        parent.AddPage(imageId=-1, page=self.panel1, select=False,
              text=u'\u4fee\u6539PassWafer')
        parent.AddPage(imageId=-1, page=self.ConfirmPassLot, select=False,
              text=u'\u4fee\u6539PassLot')
        parent.AddPage(imageId=-1, page=self.Configration, select=False,
              text=u'\u914d\u7f6e\u4fe1\u606f-\u5e2e\u52a9\u6587\u4ef6')

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(373, 240), size=wx.Size(495, 318),
              style=wx.DEFAULT_FRAME_STYLE,
              title=u'\u624b\u52a8\u6570\u636e\u5904\u7406\u8f6f\u4ef6 NewUI Ver04 --ByRoger')
        self.SetClientSize(wx.Size(485, 286))

        self.notebook1 = wx.Notebook(id=wxID_FRAME1NOTEBOOK1, name='notebook1',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(485, 286), style=0)

        self.Configration = wx.Panel(id=wxID_FRAME1CONFIGRATION,
              name=u'Configration', parent=self.notebook1, pos=wx.Point(0, 0),
              size=wx.Size(477, 259), style=wx.TAB_TRAVERSAL)

        self.ManualConvertTool = wx.Panel(id=wxID_FRAME1MANUALCONVERTTOOL,
              name=u'ManualConvertTool', parent=self.notebook1, pos=wx.Point(0,
              0), size=wx.Size(477, 259), style=wx.TAB_TRAVERSAL)

        self.MapDataTool = wx.Panel(id=wxID_FRAME1MAPDATATOOL,
              name=u'MapDataTool', parent=self.notebook1, pos=wx.Point(0, 0),
              size=wx.Size(477, 259), style=wx.TAB_TRAVERSAL)

        self.TitleStaticTextInData = wx.StaticText(id=wxID_FRAME1TITLESTATICTEXTINDATA,
              label=u'\u624b\u52a8\u6570\u636e\u5904\u7406\u5de5\u5177',
              name=u'TitleStaticTextInData', parent=self.ManualConvertTool,
              pos=wx.Point(96, 8), size=wx.Size(232, 35), style=0)
        self.TitleStaticTextInData.SetFont(wx.Font(22, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.ConfigInData = wx.StaticBox(id=wxID_FRAME1CONFIGINDATA,
              label=u'Config:', name=u'ConfigInData',
              parent=self.ManualConvertTool, pos=wx.Point(8, 56),
              size=wx.Size(360, 152), style=0)
        self.ConfigInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.DeviceStaticTextInData = wx.StaticText(id=wxID_FRAME1DEVICESTATICTEXTINDATA,
              label=u'Device:', name=u'DeviceStaticTextInData',
              parent=self.ManualConvertTool, pos=wx.Point(12, 87),
              size=wx.Size(62, 23), style=0)
        self.DeviceStaticTextInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.DeviceChoiceInData = wx.Choice(choices=[],
              id=wxID_FRAME1DEVICECHOICEINDATA, name=u'DeviceChoiceInData',
              parent=self.ManualConvertTool, pos=wx.Point(80, 88),
              size=wx.Size(147, 22), style=0)
        self.DeviceChoiceInData.Bind(wx.EVT_CHOICE,
              self.OnDeviceChoiceInDataChoice,
              id=wxID_FRAME1DEVICECHOICEINDATA)

        self.VersionStaticTextInData = wx.StaticText(id=wxID_FRAME1VERSIONSTATICTEXTINDATA,
              label=u'Version:', name=u'VersionStaticTextInData',
              parent=self.ManualConvertTool, pos=wx.Point(231, 86),
              size=wx.Size(68, 23), style=0)
        self.VersionStaticTextInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.VersionChoiceInData = wx.Choice(choices=[],
              id=wxID_FRAME1VERSIONCHOICEINDATA, name=u'VersionChoiceInData',
              parent=self.ManualConvertTool, pos=wx.Point(300, 87),
              size=wx.Size(56, 22), style=0)
        self.VersionChoiceInData.Bind(wx.EVT_CHOICE,
              self.OnVersionChoiceInDataChoice,
              id=wxID_FRAME1VERSIONCHOICEINDATA)

        self.LotNumStaticTextInData = wx.StaticText(id=wxID_FRAME1LOTNUMSTATICTEXTINDATA,
              label=u'Lot No:', name=u'LotNumStaticTextInData',
              parent=self.ManualConvertTool, pos=wx.Point(14, 129),
              size=wx.Size(61, 23), style=0)
        self.LotNumStaticTextInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.LotNoTextCtrlInData = wx.TextCtrl(id=wxID_FRAME1LOTNOTEXTCTRLINDATA,
              name=u'LotNoTextCtrlInData', parent=self.ManualConvertTool,
              pos=wx.Point(80, 130), size=wx.Size(133, 22), style=0, value=u'')
        self.LotNoTextCtrlInData.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.LotNoTextCtrlInData.Bind(wx.EVT_TEXT,
              self.OnLotNoTextCtrlInDataText,
              id=wxID_FRAME1LOTNOTEXTCTRLINDATA)

        self.LotNoButtonInData = wx.Button(id=wxID_FRAME1LOTNOBUTTONINDATA,
              label=u'...', name=u'LotNoButtonInData',
              parent=self.ManualConvertTool, pos=wx.Point(210, 129),
              size=wx.Size(19, 24), style=0)
        self.LotNoButtonInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.LotNoButtonInData.Bind(wx.EVT_BUTTON,
              self.OnLotNoButtonInDataButton, id=wxID_FRAME1LOTNOBUTTONINDATA)

        self.WaferNoStaticTextInData = wx.StaticText(id=wxID_FRAME1WAFERNOSTATICTEXTINDATA,
              label=u'WaferNo:', name=u'WaferNoStaticTextInData',
              parent=self.ManualConvertTool, pos=wx.Point(15, 172),
              size=wx.Size(80, 23), style=0)
        self.WaferNoStaticTextInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.WaferNoTextCtrlInData = wx.TextCtrl(id=wxID_FRAME1WAFERNOTEXTCTRLINDATA,
              name=u'WaferNoTextCtrlInData', parent=self.ManualConvertTool,
              pos=wx.Point(100, 173), size=wx.Size(260, 22), style=0,
              value=u'01;1~12;')
        self.WaferNoTextCtrlInData.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.WaferNoTextCtrlInData.Bind(wx.EVT_TEXT,
              self.OnWaferNoTextCtrlInDataText,
              id=wxID_FRAME1WAFERNOTEXTCTRLINDATA)

        self.GaugeInData = wx.Gauge(id=wxID_FRAME1GAUGEINDATA,
              name=u'GaugeInData', parent=self.ManualConvertTool,
              pos=wx.Point(9, 220), range=100, size=wx.Size(358, 19),
              style=wx.GA_HORIZONTAL)

        self.StartButtonInData = wx.Button(id=wxID_FRAME1STARTBUTTONINDATA,
              label=u'\u5f00\u59cb', name=u'StartButtonInData',
              parent=self.ManualConvertTool, pos=wx.Point(376, 80),
              size=wx.Size(80, 32), style=0)
        self.StartButtonInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.StartButtonInData.Bind(wx.EVT_BUTTON,
              self.OnStartButtonInDataButton, id=wxID_FRAME1STARTBUTTONINDATA)

        self.ReConfigButtonInData = wx.Button(id=wxID_FRAME1RECONFIGBUTTONINDATA,
              label=u'\u6e05\u9664\u914d\u7f6e', name=u'ReConfigButtonInData',
              parent=self.ManualConvertTool, pos=wx.Point(376, 144),
              size=wx.Size(80, 32), style=0)
        self.ReConfigButtonInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ReConfigButtonInData.Bind(wx.EVT_BUTTON,
              self.OnReConfigButtonInDataButton,
              id=wxID_FRAME1RECONFIGBUTTONINDATA)

        self.ExitButtonInData = wx.Button(id=wxID_FRAME1EXITBUTTONINDATA,
              label=u'\u9000\u51fa', name=u'ExitButtonInData',
              parent=self.ManualConvertTool, pos=wx.Point(376, 208),
              size=wx.Size(80, 32), style=0)
        self.ExitButtonInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ExitButtonInData.Bind(wx.EVT_BUTTON, self.OnExitButtonInDataButton,
              id=wxID_FRAME1EXITBUTTONINDATA)

        self.TestDataPathStaticTextInConfigration = wx.StaticText(id=wxID_FRAME1TESTDATAPATHSTATICTEXTINCONFIGRATION,
              label=u'TestDataPath:',
              name=u'TestDataPathStaticTextInConfigration',
              parent=self.Configration, pos=wx.Point(19, 13), size=wx.Size(118,
              23), style=0)
        self.TestDataPathStaticTextInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.TestDataPathTextCtrlInCofigration = wx.TextCtrl(id=wxID_FRAME1TESTDATAPATHTEXTCTRLINCOFIGRATION,
              name=u'TestDataPathTextCtrlInCofigration',
              parent=self.Configration, pos=wx.Point(15, 42), size=wx.Size(283,
              22), style=0, value=u'')
        self.TestDataPathTextCtrlInCofigration.Bind(wx.EVT_TEXT,
              self.OnTestDataPathTextCtrlInCofigrationText,
              id=wxID_FRAME1TESTDATAPATHTEXTCTRLINCOFIGRATION)

        self.TestDataPathButtonInConfigration = wx.Button(id=wxID_FRAME1TESTDATAPATHBUTTONINCONFIGRATION,
              label=u'...', name=u'TestDataPathButtonInConfigration',
              parent=self.Configration, pos=wx.Point(299, 41), size=wx.Size(40,
              26), style=0)
        self.TestDataPathButtonInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.TestDataPathButtonInConfigration.Bind(wx.EVT_BUTTON,
              self.OnTestDataPathButtonInConfigrationButton,
              id=wxID_FRAME1TESTDATAPATHBUTTONINCONFIGRATION)

        self.SortTypeRadioBoxInData = wx.RadioBox(choices=['Sort1', 'Sort2'],
              id=wxID_FRAME1SORTTYPERADIOBOXINDATA, label=u'SortType:',
              majorDimension=2, name=u'SortTypeRadioBoxInData',
              parent=self.ManualConvertTool, point=wx.Point(234, 113),
              size=wx.Size(122, 55), style=wx.RA_SPECIFY_COLS)
        self.SortTypeRadioBoxInData.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL,
              wx.BOLD, False, u'Tahoma'))
        self.SortTypeRadioBoxInData.Bind(wx.EVT_RADIOBOX,
              self.OnSortTypeRadioBoxInDataRadiobox,
              id=wxID_FRAME1SORTTYPERADIOBOXINDATA)

        self.TitileInMapData = wx.StaticText(id=wxID_FRAME1TITILEINMAPDATA,
              label=u'MapData \u5904\u7406\u5de5\u5177 ',
              name=u'TitileInMapData', parent=self.MapDataTool, pos=wx.Point(60,
              8), size=wx.Size(247, 35), style=0)
        self.TitileInMapData.SetFont(wx.Font(22, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.ConfigStaticBoxInMapData = wx.StaticBox(id=wxID_FRAME1CONFIGSTATICBOXINMAPDATA,
              label=u'Config', name=u'ConfigStaticBoxInMapData',
              parent=self.MapDataTool, pos=wx.Point(8, 48), size=wx.Size(352,
              208), style=0)

        self.DeviceStaticTextInMapData = wx.StaticText(id=wxID_FRAME1DEVICESTATICTEXTINMAPDATA,
              label=u'Device:', name=u'DeviceStaticTextInMapData',
              parent=self.MapDataTool, pos=wx.Point(18, 76), size=wx.Size(62,
              23), style=0)
        self.DeviceStaticTextInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.VersionStaticTextInMapData = wx.StaticText(id=wxID_FRAME1VERSIONSTATICTEXTINMAPDATA,
              label=u'Version:', name=u'VersionStaticTextInMapData',
              parent=self.MapDataTool, pos=wx.Point(203, 78), size=wx.Size(68,
              23), style=0)
        self.VersionStaticTextInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.LotNoStaticTextInMapData = wx.StaticText(id=wxID_FRAME1LOTNOSTATICTEXTINMAPDATA,
              label=u'LotNo:', name=u'LotNoStaticTextInMapData',
              parent=self.MapDataTool, pos=wx.Point(20, 128), size=wx.Size(55,
              23), style=0)
        self.LotNoStaticTextInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.LotNoTextCtrlInMapData = wx.TextCtrl(id=wxID_FRAME1LOTNOTEXTCTRLINMAPDATA,
              name=u'LotNoTextCtrlInMapData', parent=self.MapDataTool,
              pos=wx.Point(84, 131), size=wx.Size(228, 22), style=0, value=u'')
        self.LotNoTextCtrlInMapData.Bind(wx.EVT_TEXT,
              self.OnLotNoTextCtrlInMapDataText,
              id=wxID_FRAME1LOTNOTEXTCTRLINMAPDATA)

        self.LotNoButtonInMapData = wx.Button(id=wxID_FRAME1LOTNOBUTTONINMAPDATA,
              label=u'...', name=u'LotNoButtonInMapData',
              parent=self.MapDataTool, pos=wx.Point(312, 129), size=wx.Size(40,
              25), style=0)
        self.LotNoButtonInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.LotNoButtonInMapData.Bind(wx.EVT_BUTTON,
              self.OnLotNoButtonInMapDataButton,
              id=wxID_FRAME1LOTNOBUTTONINMAPDATA)

        self.SortTypeRadioBoxInMapData = wx.RadioBox(choices=['Sort1', 'Sort2',
              'All Type'], id=wxID_FRAME1SORTTYPERADIOBOXINMAPDATA,
              label=u'SortType:', majorDimension=3,
              name=u'SortTypeRadioBoxInMapData', parent=self.MapDataTool,
              point=wx.Point(22, 176), size=wx.Size(328, 64),
              style=wx.RA_SPECIFY_COLS)
        self.SortTypeRadioBoxInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.SortTypeRadioBoxInMapData.SetExtraStyle(1)
        self.SortTypeRadioBoxInMapData.Bind(wx.EVT_RADIOBOX,
              self.OnSortTypeRadioBoxInMapDataRadiobox,
              id=wxID_FRAME1SORTTYPERADIOBOXINMAPDATA)

        self.StartButtonInMapData = wx.Button(id=wxID_FRAME1STARTBUTTONINMAPDATA,
              label=u'\u5f00\u59cb', name=u'StartButtonInMapData',
              parent=self.MapDataTool, pos=wx.Point(384, 80), size=wx.Size(75,
              32), style=0)
        self.StartButtonInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.StartButtonInMapData.Bind(wx.EVT_BUTTON,
              self.OnStartButtonInMapDataButton,
              id=wxID_FRAME1STARTBUTTONINMAPDATA)

        self.ViewButtonInMapData = wx.Button(id=wxID_FRAME1VIEWBUTTONINMAPDATA,
              label=u'\u67e5\u770b', name=u'ViewButtonInMapData',
              parent=self.MapDataTool, pos=wx.Point(384, 144), size=wx.Size(75,
              32), style=0)
        self.ViewButtonInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ViewButtonInMapData.Bind(wx.EVT_BUTTON,
              self.OnViewButtonInMapDataButton,
              id=wxID_FRAME1VIEWBUTTONINMAPDATA)

        self.ExitButtonInMapData = wx.Button(id=wxID_FRAME1EXITBUTTONINMAPDATA,
              label=u'\u9000\u51fa', name=u'ExitButtonInMapData',
              parent=self.MapDataTool, pos=wx.Point(384, 208), size=wx.Size(75,
              32), style=0)
        self.ExitButtonInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ExitButtonInMapData.Bind(wx.EVT_BUTTON,
              self.OnExitButtonInMapDataButton,
              id=wxID_FRAME1EXITBUTTONINMAPDATA)

        self.DeviceChoiceInMapData = wx.Choice(choices=[],
              id=wxID_FRAME1DEVICECHOICEINMAPDATA,
              name=u'DeviceChoiceInMapData', parent=self.MapDataTool,
              pos=wx.Point(88, 80), size=wx.Size(112, 22), style=0)
        self.DeviceChoiceInMapData.Bind(wx.EVT_CHOICE,
              self.OnDeviceChoiceInMapDataChoice,
              id=wxID_FRAME1DEVICECHOICEINMAPDATA)

        self.VersionChoiceInMapData = wx.Choice(choices=[],
              id=wxID_FRAME1VERSIONCHOICEINMAPDATA,
              name=u'VersionChoiceInMapData', parent=self.MapDataTool,
              pos=wx.Point(269, 81), size=wx.Size(80, 22), style=0)
        self.VersionChoiceInMapData.Bind(wx.EVT_CHOICE,
              self.OnVersionChoiceInMapDataChoice,
              id=wxID_FRAME1VERSIONCHOICEINMAPDATA)

        self.WaferMapView = wx.Panel(id=wxID_FRAME1WAFERMAPVIEW,
              name=u'WaferMapView', parent=self.notebook1, pos=wx.Point(0, 0),
              size=wx.Size(477, 259), style=wx.TAB_TRAVERSAL)

        self.TitleStaticTextInWaferMap = wx.StaticText(id=wxID_FRAME1TITLESTATICTEXTINWAFERMAP,
              label=u'WaferMap \u67e5\u770b\u5de5\u5177',
              name=u'TitleStaticTextInWaferMap', parent=self.WaferMapView,
              pos=wx.Point(80, 24), size=wx.Size(253, 35), style=0)
        self.TitleStaticTextInWaferMap.SetFont(wx.Font(22, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.ConfigStaticBoxInWaferMap = wx.StaticBox(id=wxID_FRAME1CONFIGSTATICBOXINWAFERMAP,
              label=u'Config', name=u'ConfigStaticBoxInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(8, 72), size=wx.Size(368,
              176), style=0)
        self.ConfigStaticBoxInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.DeviceStaticTextInWaferMap = wx.StaticText(id=wxID_FRAME1DEVICESTATICTEXTINWAFERMAP,
              label=u'Device:', name=u'DeviceStaticTextInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(16, 101), size=wx.Size(62,
              23), style=0)
        self.DeviceStaticTextInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.DeviceChoiceInWaferMap = wx.Choice(choices=[],
              id=wxID_FRAME1DEVICECHOICEINWAFERMAP,
              name=u'DeviceChoiceInWaferMap', parent=self.WaferMapView,
              pos=wx.Point(80, 104), size=wx.Size(140, 22), style=0)
        self.DeviceChoiceInWaferMap.Bind(wx.EVT_CHOICE,
              self.OnDeviceChoiceInWaferMapChoice,
              id=wxID_FRAME1DEVICECHOICEINWAFERMAP)

        self.VersionStaticTextInWaferMap = wx.StaticText(id=wxID_FRAME1VERSIONSTATICTEXTINWAFERMAP,
              label=u'Version:', name=u'VersionStaticTextInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(225, 104), size=wx.Size(68,
              23), style=0)
        self.VersionStaticTextInWaferMap.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.VersionChoiceInWaferMap = wx.Choice(choices=[],
              id=wxID_FRAME1VERSIONCHOICEINWAFERMAP,
              name=u'VersionChoiceInWaferMap', parent=self.WaferMapView,
              pos=wx.Point(296, 104), size=wx.Size(73, 22), style=0)
        self.VersionChoiceInWaferMap.Bind(wx.EVT_CHOICE,
              self.OnVersionChoiceInWaferMapChoice,
              id=wxID_FRAME1VERSIONCHOICEINWAFERMAP)

        self.LotNumStaticTextInWaferMap = wx.StaticText(id=wxID_FRAME1LOTNUMSTATICTEXTINWAFERMAP,
              label=u'Lot No:', name=u'LotNumStaticTextInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(16, 151), size=wx.Size(61,
              23), style=0)
        self.LotNumStaticTextInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.LotNumTextCtrlInWaferMap = wx.TextCtrl(id=wxID_FRAME1LOTNUMTEXTCTRLINWAFERMAP,
              name=u'LotNumTextCtrlInWaferMap', parent=self.WaferMapView,
              pos=wx.Point(80, 154), size=wx.Size(120, 22), style=0, value=u'')
        self.LotNumTextCtrlInWaferMap.Bind(wx.EVT_TEXT,
              self.OnLotNumTextCtrlInWaferMapText,
              id=wxID_FRAME1LOTNUMTEXTCTRLINWAFERMAP)

        self.SortTypeRadioBoxInWaferMap = wx.RadioBox(choices=['Sort1',
              'Sort2'], id=wxID_FRAME1SORTTYPERADIOBOXINWAFERMAP,
              label=u'SortType', majorDimension=2,
              name=u'SortTypeRadioBoxInWaferMap', parent=self.WaferMapView,
              point=wx.Point(232, 136), size=(135, 49),
              style=wx.RA_SPECIFY_COLS)
        self.SortTypeRadioBoxInWaferMap.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL,
              wx.BOLD, False, u'Tahoma'))
        self.SortTypeRadioBoxInWaferMap.Bind(wx.EVT_RADIOBOX,
              self.OnSortTypeRadioBoxInWaferMapRadiobox,
              id=wxID_FRAME1SORTTYPERADIOBOXINWAFERMAP)

        self.LotNoButtonInWaferMap = wx.Button(id=wxID_FRAME1LOTNOBUTTONINWAFERMAP,
              label=u'...', name=u'LotNoButtonInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(198, 153), size=wx.Size(24,
              24), style=0)
        self.LotNoButtonInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.LotNoButtonInWaferMap.Bind(wx.EVT_BUTTON,
              self.OnLotNoButtonInWaferMapButton,
              id=wxID_FRAME1LOTNOBUTTONINWAFERMAP)

        self.WaferNoStaticTextInWaferMap = wx.StaticText(id=wxID_FRAME1WAFERNOSTATICTEXTINWAFERMAP,
              label=u'WaferNo:', name=u'WaferNoStaticTextInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(18, 200), size=wx.Size(80,
              23), style=0)
        self.WaferNoStaticTextInWaferMap.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.WaferNoTextCtrlInWaferMap = wx.TextCtrl(id=wxID_FRAME1WAFERNOTEXTCTRLINWAFERMAP,
              name=u'WaferNoTextCtrlInWaferMap', parent=self.WaferMapView,
              pos=wx.Point(102, 203), size=wx.Size(266, 22), style=0,
              value=u'01;1~12;')
        self.WaferNoTextCtrlInWaferMap.Bind(wx.EVT_TEXT,
              self.OnWaferNoTextCtrlInWaferMapText,
              id=wxID_FRAME1WAFERNOTEXTCTRLINWAFERMAP)

        self.StartButtonInWaferMap = wx.Button(id=wxID_FRAME1STARTBUTTONINWAFERMAP,
              label=u'\u67e5\u770b', name=u'StartButtonInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(392, 82), size=wx.Size(75,
              32), style=0)
        self.StartButtonInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.StartButtonInWaferMap.Bind(wx.EVT_BUTTON,
              self.OnStartButtonInWaferMapButton,
              id=wxID_FRAME1STARTBUTTONINWAFERMAP)

        self.NextButtonInWaferMap = wx.Button(id=wxID_FRAME1NEXTBUTTONINWAFERMAP,
              label=u'\u540e\u4e00\u7247', name=u'NextButtonInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(392, 128), size=wx.Size(75,
              32), style=0)
        self.NextButtonInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.NextButtonInWaferMap.Bind(wx.EVT_BUTTON,
              self.OnNextButtonInWaferMapButton,
              id=wxID_FRAME1NEXTBUTTONINWAFERMAP)

        self.PreButtonInWaferMap = wx.Button(id=wxID_FRAME1PREBUTTONINWAFERMAP,
              label=u'\u524d\u4e00\u7247', name=u'PreButtonInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(392, 173), size=wx.Size(75,
              32), style=0)
        self.PreButtonInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.PreButtonInWaferMap.Bind(wx.EVT_BUTTON,
              self.OnPreButtonInWaferMapButton,
              id=wxID_FRAME1PREBUTTONINWAFERMAP)

        self.ExitButtonInWaferMap = wx.Button(id=wxID_FRAME1EXITBUTTONINWAFERMAP,
              label=u'\u9000\u51fa', name=u'ExitButtonInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(392, 216), size=wx.Size(75,
              32), style=0)
        self.ExitButtonInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ExitButtonInWaferMap.Bind(wx.EVT_BUTTON,
              self.OnExitButtonInWaferMapButton,
              id=wxID_FRAME1EXITBUTTONINWAFERMAP)

        self.ConfigDeviceStatictTextInConfigration = wx.StaticBox(id=wxID_FRAME1CONFIGDEVICESTATICTTEXTINCONFIGRATION,
              label=u'ConfigDevice',
              name=u'ConfigDeviceStatictTextInConfigration',
              parent=self.Configration, pos=wx.Point(8, 84), size=wx.Size(464,
              172), style=0)
        self.ConfigDeviceStatictTextInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.DeviceNameStaticTextInConfigration = wx.StaticText(id=wxID_FRAME1DEVICENAMESTATICTEXTINCONFIGRATION,
              label=u'Device   Name:',
              name=u'DeviceNameStaticTextInConfigration',
              parent=self.Configration, pos=wx.Point(22, 107), size=wx.Size(129,
              23), style=0)
        self.DeviceNameStaticTextInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.DeviceNameTextCtrlInConfigration = wx.TextCtrl(id=wxID_FRAME1DEVICENAMETEXTCTRLINCONFIGRATION,
              name=u'DeviceNameTextCtrlInConfigration',
              parent=self.Configration, pos=wx.Point(155, 106),
              size=wx.Size(109, 22), style=0, value=u'')
        self.DeviceNameTextCtrlInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.DeviceNameTextCtrlInConfigration.Bind(wx.EVT_TEXT,
              self.OnDeviceNameTextCtrlInConfigrationText,
              id=wxID_FRAME1DEVICENAMETEXTCTRLINCONFIGRATION)

        self.DeviceVersionStaticTextInCofigration = wx.StaticText(id=wxID_FRAME1DEVICEVERSIONSTATICTEXTINCOFIGRATION,
              label=u'Device Version:',
              name=u'DeviceVersionStaticTextInCofigration',
              parent=self.Configration, pos=wx.Point(22, 145), size=wx.Size(129,
              23), style=0)
        self.DeviceVersionStaticTextInCofigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.DeviceVersionTextCtrlInConfigration = wx.TextCtrl(id=wxID_FRAME1DEVICEVERSIONTEXTCTRLINCONFIGRATION,
              name=u'DeviceVersionTextCtrlInConfigration',
              parent=self.Configration, pos=wx.Point(155, 145),
              size=wx.Size(109, 22), style=0, value=u'')
        self.DeviceVersionTextCtrlInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.DeviceVersionTextCtrlInConfigration.Bind(wx.EVT_TEXT,
              self.OnDeviceVersionTextCtrlInConfigrationText,
              id=wxID_FRAME1DEVICEVERSIONTEXTCTRLINCONFIGRATION)

        self.SortTypeRadioBoxInConfigration = wx.RadioBox(choices=['Sort0 ',
              'Sort1 ', 'Sort2 '], id=wxID_FRAME1SORTTYPERADIOBOXINCONFIGRATION,
              label=u'SortType:', majorDimension=3,
              name=u'SortTypeRadioBoxInConfigration', parent=self.Configration,
              point=wx.Point(280, 95), size=wx.Size(185, 45),
              style=wx.RA_SPECIFY_COLS)
        self.SortTypeRadioBoxInConfigration.SetFont(wx.Font(9, wx.SWISS,
              wx.NORMAL, wx.BOLD, False, u'Tahoma'))
        self.SortTypeRadioBoxInConfigration.SetBestFittingSize(wx.Size(185, 45))
        self.SortTypeRadioBoxInConfigration.Bind(wx.EVT_RADIOBOX,
              self.OnSortTypeRadioBoxInConfigrationRadiobox,
              id=wxID_FRAME1SORTTYPERADIOBOXINCONFIGRATION)

        self.PathStaticTextInConfigration = wx.StaticText(id=wxID_FRAME1PATHSTATICTEXTINCONFIGRATION,
              label=u'Path:', name=u'PathStaticTextInConfigration',
              parent=self.Configration, pos=wx.Point(285, 147), size=wx.Size(44,
              23), style=0)
        self.PathStaticTextInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.PathTextCtrlInConfigration = wx.TextCtrl(id=wxID_FRAME1PATHTEXTCTRLINCONFIGRATION,
              name=u'PathTextCtrlInConfigration', parent=self.Configration,
              pos=wx.Point(335, 147), size=wx.Size(127, 22), style=0,
              value=u'')
        self.PathTextCtrlInConfigration.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.PathTextCtrlInConfigration.Bind(wx.EVT_TEXT,
              self.OnPathTextCtrlInConfigrationText,
              id=wxID_FRAME1PATHTEXTCTRLINCONFIGRATION)

        self.TestDataFileStaticTextInConfigration = wx.StaticText(id=wxID_FRAME1TESTDATAFILESTATICTEXTINCONFIGRATION,
              label=u'Test Data File :',
              name=u'TestDataFileStaticTextInConfigration',
              parent=self.Configration, pos=wx.Point(25, 184), size=wx.Size(127,
              23), style=0)
        self.TestDataFileStaticTextInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.TestDataFileTextCtrlInConfigration = wx.TextCtrl(id=wxID_FRAME1TESTDATAFILETEXTCTRLINCONFIGRATION,
              name=u'TestDataFileTextCtrlInConfigration',
              parent=self.Configration, pos=wx.Point(158, 184),
              size=wx.Size(272, 22), style=wx.SUNKEN_BORDER, value=u'')
        self.TestDataFileTextCtrlInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.TestDataFileTextCtrlInConfigration.Bind(wx.EVT_TEXT,
              self.OnTestDataFileTextCtrlInConfigrationText,
              id=wxID_FRAME1TESTDATAFILETEXTCTRLINCONFIGRATION)

        self.TestDataFileButtonInConfigration = wx.Button(id=wxID_FRAME1TESTDATAFILEBUTTONINCONFIGRATION,
              label=u'...', name=u'TestDataFileButtonInConfigration',
              parent=self.Configration, pos=wx.Point(429, 184), size=wx.Size(32,
              26), style=0)
        self.TestDataFileButtonInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.TestDataFileButtonInConfigration.Bind(wx.EVT_BUTTON,
              self.OnTestDataFileButtonInConfigrationButton,
              id=wxID_FRAME1TESTDATAFILEBUTTONINCONFIGRATION)

        self.StartButtonInConfigration = wx.Button(id=wxID_FRAME1STARTBUTTONINCONFIGRATION,
              label=u'\u5f00\u59cb', name=u'StartButtonInConfigration',
              parent=self.Configration, pos=wx.Point(64, 214), size=wx.Size(75,
              32), style=0)
        self.StartButtonInConfigration.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.StartButtonInConfigration.Bind(wx.EVT_BUTTON,
              self.OnStartButtonInConfigrationButton,
              id=wxID_FRAME1STARTBUTTONINCONFIGRATION)

        self.ReConfigButtonInConfigration = wx.Button(id=wxID_FRAME1RECONFIGBUTTONINCONFIGRATION,
              label=u'\u6e05\u9664\u914d\u7f6e',
              name=u'ReConfigButtonInConfigration', parent=self.Configration,
              pos=wx.Point(200, 214), size=wx.Size(85, 32), style=0)
        self.ReConfigButtonInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.ReConfigButtonInConfigration.Bind(wx.EVT_BUTTON,
              self.OnReConfigButtonInConfigrationButton,
              id=wxID_FRAME1RECONFIGBUTTONINCONFIGRATION)

        self.ExitButtonInConfigration = wx.Button(id=wxID_FRAME1EXITBUTTONINCONFIGRATION,
              label=u'\u9000\u51fa', name=u'ExitButtonInConfigration',
              parent=self.Configration, pos=wx.Point(341, 214), size=wx.Size(85,
              32), style=0)
        self.ExitButtonInConfigration.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ExitButtonInConfigration.Bind(wx.EVT_BUTTON,
              self.OnExitButtonInConfigrationButton,
              id=wxID_FRAME1EXITBUTTONINCONFIGRATION)

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1',
              parent=self.notebook1, pos=wx.Point(0, 0), size=wx.Size(477, 259),
              style=wx.TAB_TRAVERSAL)

        self.HeadStaticTextInModifyPassWafer = wx.StaticText(id=wxID_FRAME1HEADSTATICTEXTINMODIFYPASSWAFER,
              label=u'\u5220\u9664\u81ea\u52a8\u8f6c\u6362\u8fc7\u7684Wafer\u4fe1\u606f',
              name=u'HeadStaticTextInModifyPassWafer', parent=self.panel1,
              pos=wx.Point(56, 24), size=wx.Size(365, 35), style=0)
        self.HeadStaticTextInModifyPassWafer.SetFont(wx.Font(22, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.DeviceNameStaticTextInModifyPassWafer = wx.StaticText(id=wxID_FRAME1DEVICENAMESTATICTEXTINMODIFYPASSWAFER,
              label=u'Device:', name=u'DeviceNameStaticTextInModifyPassWafer',
              parent=self.panel1, pos=wx.Point(15, 88), size=wx.Size(62, 23),
              style=0)
        self.DeviceNameStaticTextInModifyPassWafer.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.DeviceNameChoiceInModifyPassWafer = wx.Choice(choices=[],
              id=wxID_FRAME1DEVICENAMECHOICEINMODIFYPASSWAFER,
              name=u'DeviceNameChoiceInModifyPassWafer', parent=self.panel1,
              pos=wx.Point(95, 88), size=wx.Size(170, 22), style=0)
        self.DeviceNameChoiceInModifyPassWafer.SetAutoLayout(True)
        self.DeviceNameChoiceInModifyPassWafer.SetBestFittingSize(wx.Size(170,
              22))
        self.DeviceNameChoiceInModifyPassWafer.Enable(True)
        self.DeviceNameChoiceInModifyPassWafer.SetExtraStyle(1)
        self.DeviceNameChoiceInModifyPassWafer.Bind(wx.EVT_CHOICE,
              self.OnDeviceNameChoiceInModifyPassWaferChoice,
              id=wxID_FRAME1DEVICENAMECHOICEINMODIFYPASSWAFER)

        self.LotNoStaticTextInModifyPassWafer = wx.StaticText(id=wxID_FRAME1LOTNOSTATICTEXTINMODIFYPASSWAFER,
              label=u'Lot No:', name=u'LotNoStaticTextInModifyPassWafer',
              parent=self.panel1, pos=wx.Point(15, 128), size=wx.Size(61, 23),
              style=0)
        self.LotNoStaticTextInModifyPassWafer.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.LotNoTextCtrlInModifyPassWafer = wx.TextCtrl(id=wxID_FRAME1LOTNOTEXTCTRLINMODIFYPASSWAFER,
              name=u'LotNoTextCtrlInModifyPassWafer', parent=self.panel1,
              pos=wx.Point(95, 128), size=wx.Size(148, 22), style=0, value=u'')
        self.LotNoTextCtrlInModifyPassWafer.SetFont(wx.Font(12, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.LotNoTextCtrlInModifyPassWafer.Bind(wx.EVT_TEXT,
              self.OnLotNoTextCtrlInModifyPassWaferText,
              id=wxID_FRAME1LOTNOTEXTCTRLINMODIFYPASSWAFER)

        self.LotNoButtonInModifyPassWafer = wx.Button(id=wxID_FRAME1LOTNOBUTTONINMODIFYPASSWAFER,
              label=u'...', name=u'LotNoButtonInModifyPassWafer',
              parent=self.panel1, pos=wx.Point(242, 127), size=wx.Size(26, 24),
              style=0)
        self.LotNoButtonInModifyPassWafer.SetFont(wx.Font(12, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.LotNoButtonInModifyPassWafer.Bind(wx.EVT_BUTTON,
              self.OnLotNoButtonInModifyPassWaferButton,
              id=wxID_FRAME1LOTNOBUTTONINMODIFYPASSWAFER)

        self.WaferIdStaticTextInModifyPassWafer = wx.StaticText(id=wxID_FRAME1WAFERIDSTATICTEXTINMODIFYPASSWAFER,
              label=u'WaferNo:', name=u'WaferIdStaticTextInModifyPassWafer',
              parent=self.panel1, pos=wx.Point(15, 176), size=wx.Size(80, 23),
              style=0)
        self.WaferIdStaticTextInModifyPassWafer.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.WaferIdTextCtrlInModifyPassWafer = wx.TextCtrl(id=wxID_FRAME1WAFERIDTEXTCTRLINMODIFYPASSWAFER,
              name=u'WaferIdTextCtrlInModifyPassWafer', parent=self.panel1,
              pos=wx.Point(95, 175), size=wx.Size(360, 22), style=0,
              value=u'01;1~12;')
        self.WaferIdTextCtrlInModifyPassWafer.SetFont(wx.Font(12, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.WaferIdTextCtrlInModifyPassWafer.Bind(wx.EVT_TEXT,
              self.OnWaferIdTextCtrlInModifyPassWafer,
              id=wxID_FRAME1WAFERIDTEXTCTRLINMODIFYPASSWAFER)

        self.SortTypesRadioBoxInModifyPassWafer = wx.RadioBox(choices=['  Sort1    ',
              '  Sort2'], id=wxID_FRAME1SORTTYPESRADIOBOXINMODIFYPASSWAFER,
              label=u'Sort Type:', majorDimension=2,
              name=u'SortTypesRadioBoxInModifyPassWafer', parent=self.panel1,
              point=wx.Point(278, 115), size=wx.Size(170, 45),
              style=wx.RA_SPECIFY_COLS)
        self.SortTypesRadioBoxInModifyPassWafer.SetFont(wx.Font(12, wx.SWISS,
              wx.NORMAL, wx.BOLD, False, u'Tahoma'))
        self.SortTypesRadioBoxInModifyPassWafer.Bind(wx.EVT_RADIOBOX,
              self.OnSortTypesRadioBoxInModifyPassWaferRadiobox,
              id=wxID_FRAME1SORTTYPESRADIOBOXINMODIFYPASSWAFER)

        self.DeleteButtonInModifyPassWafer = wx.Button(id=wxID_FRAME1DELETEBUTTONINMODIFYPASSWAFER,
              label=u'\u5220\u9664', name=u'DeleteButtonInModifyPassWafer',
              parent=self.panel1, pos=wx.Point(56, 217), size=wx.Size(75, 32),
              style=0)
        self.DeleteButtonInModifyPassWafer.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.DeleteButtonInModifyPassWafer.Bind(wx.EVT_BUTTON,
              self.OnDeleteButtonInModifyPassWaferButton,
              id=wxID_FRAME1DELETEBUTTONINMODIFYPASSWAFER)

        self.ReConfButtonInModifyPassWafer = wx.Button(id=wxID_FRAME1RECONFBUTTONINMODIFYPASSWAFER,
              label=u'\u6e05\u9664\u914d\u7f6e',
              name=u'ReConfButtonInModifyPassWafer', parent=self.panel1,
              pos=wx.Point(208, 217), size=wx.Size(83, 32), style=0)
        self.ReConfButtonInModifyPassWafer.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.ReConfButtonInModifyPassWafer.Bind(wx.EVT_BUTTON,
              self.OnReConfButtonInModifyPassWaferButton,
              id=wxID_FRAME1RECONFBUTTONINMODIFYPASSWAFER)

        self.ExitButtonInModifyPassWafer = wx.Button(id=wxID_FRAME1EXITBUTTONINMODIFYPASSWAFER,
              label=u'\u9000\u51fa', name=u'ExitButtonInModifyPassWafer',
              parent=self.panel1, pos=wx.Point(374, 217), size=wx.Size(75, 32),
              style=0)
        self.ExitButtonInModifyPassWafer.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.ExitButtonInModifyPassWafer.Bind(wx.EVT_BUTTON,
              self.OnExitButtonInModifyPassWaferButton,
              id=wxID_FRAME1EXITBUTTONINMODIFYPASSWAFER)

        self.VersionStaticTextInModifyPassWafer = wx.StaticText(id=wxID_FRAME1VERSIONSTATICTEXTINMODIFYPASSWAFER,
              label=u'Version:', name=u'VersionStaticTextInModifyPassWafer',
              parent=self.panel1, pos=wx.Point(280, 88), size=wx.Size(68, 23),
              style=0)
        self.VersionStaticTextInModifyPassWafer.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.VersionChoiceInModifyPassWafer = wx.Choice(choices=[],
              id=wxID_FRAME1VERSIONCHOICEINMODIFYPASSWAFER,
              name=u'VersionChoiceInModifyPassWafer', parent=self.panel1,
              pos=wx.Point(354, 88), size=wx.Size(96, 22), style=0)
        self.VersionChoiceInModifyPassWafer.Bind(wx.EVT_CHOICE,
              self.OnVersionChoiceInModifyPassWaferChoice,
              id=wxID_FRAME1VERSIONCHOICEINMODIFYPASSWAFER)

        self.ConfirmPassLot = wx.Panel(id=wxID_FRAME1CONFIRMPASSLOT,
              name=u'ConfirmPassLot', parent=self.notebook1, pos=wx.Point(0, 0),
              size=wx.Size(477, 259), style=wx.TAB_TRAVERSAL)

        self.HeadStaticTextInConfirmPassLot = wx.StaticText(id=wxID_FRAME1HEADSTATICTEXTINCONFIRMPASSLOT,
              label=u'\u786e\u8ba4PassLot\u5de5\u5177',
              name=u'HeadStaticTextInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(120, 16),
              size=wx.Size(213, 35), style=0)
        self.HeadStaticTextInConfirmPassLot.SetFont(wx.Font(22, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.DeviceStaticTextInConfirmPassLot = wx.StaticText(id=wxID_FRAME1DEVICESTATICTEXTINCONFIRMPASSLOT,
              label=u'Device:', name=u'DeviceStaticTextInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(24, 72), size=wx.Size(62,
              23), style=0)
        self.DeviceStaticTextInConfirmPassLot.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.DeviceChoiceInConfirmPassLot = wx.Choice(choices=[],
              id=wxID_FRAME1DEVICECHOICEINCONFIRMPASSLOT,
              name=u'DeviceChoiceInConfirmPassLot', parent=self.ConfirmPassLot,
              pos=wx.Point(88, 74), size=wx.Size(130, 22), style=0)
        self.DeviceChoiceInConfirmPassLot.Bind(wx.EVT_CHOICE,
              self.OnDeviceChoiceInConfirmPassLotChoice,
              id=wxID_FRAME1DEVICECHOICEINCONFIRMPASSLOT)

        self.VersionStaticTextInConfirmPassLot = wx.StaticText(id=wxID_FRAME1VERSIONSTATICTEXTINCONFIRMPASSLOT,
              label=u'Ver  :', name=u'VersionStaticTextInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(233, 75),
              size=wx.Size(47, 23), style=0)
        self.VersionStaticTextInConfirmPassLot.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.VersionChoiceInConfirmPassLot = wx.Choice(choices=[],
              id=wxID_FRAME1VERSIONCHOICEINCONFIRMPASSLOT, name='choice1',
              parent=self.ConfirmPassLot, pos=wx.Point(280, 75),
              size=wx.Size(96, 22), style=0)
        self.VersionChoiceInConfirmPassLot.Bind(wx.EVT_CHOICE,
              self.OnVersionChoiceInConfirmPassLotChoice,
              id=wxID_FRAME1VERSIONCHOICEINCONFIRMPASSLOT)

        self.LotNoStaticTextInConfirmPassLot = wx.StaticText(id=wxID_FRAME1LOTNOSTATICTEXTINCONFIRMPASSLOT,
              label=u'Lot No:', name=u'LotNoStaticTextInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(24, 112),
              size=wx.Size(61, 23), style=0)
        self.LotNoStaticTextInConfirmPassLot.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.LotNoTextCtrlInConfirmPassLot = wx.TextCtrl(id=wxID_FRAME1LOTNOTEXTCTRLINCONFIRMPASSLOT,
              name=u'LotNoTextCtrlInConfirmPassLot', parent=self.ConfirmPassLot,
              pos=wx.Point(88, 113), size=wx.Size(103, 22), style=0, value=u'')
        self.LotNoTextCtrlInConfirmPassLot.Bind(wx.EVT_TEXT,
              self.OnLotNoTextCtrlInConfirmPassLotText,
              id=wxID_FRAME1LOTNOTEXTCTRLINCONFIRMPASSLOT)

        self.LotNoButtonInConfirmPassLot = wx.Button(id=wxID_FRAME1LOTNOBUTTONINCONFIRMPASSLOT,
              label=u'...', name=u'LotNoButtonInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(190, 112),
              size=wx.Size(29, 24), style=0)
        self.LotNoButtonInConfirmPassLot.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.LotNoButtonInConfirmPassLot.Bind(wx.EVT_BUTTON,
              self.OnLotNoButtonInConfirmPassLotButton,
              id=wxID_FRAME1LOTNOBUTTONINCONFIRMPASSLOT)

        self.RespStaticTextInConfirmPassLot = wx.StaticText(id=wxID_FRAME1RESPSTATICTEXTINCONFIRMPASSLOT,
              label=u'Resp:', name=u'RespStaticTextInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(232, 110),
              size=wx.Size(48, 23), style=0)
        self.RespStaticTextInConfirmPassLot.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.RespChoiceInConfirmPassLot = wx.Choice(choices=[],
              id=wxID_FRAME1RESPCHOICEINCONFIRMPASSLOT,
              name=u'RespChoiceInConfirmPassLot', parent=self.ConfirmPassLot,
              pos=wx.Point(280, 112), size=wx.Size(96, 22), style=0)
        self.RespChoiceInConfirmPassLot.Bind(wx.EVT_CHOICE,
              self.OnRespChoiceInConfirmPassLotChoice,
              id=wxID_FRAME1RESPCHOICEINCONFIRMPASSLOT)

        self.StartButtonInConfirmPassLot = wx.Button(id=wxID_FRAME1STARTBUTTONINCONFIRMPASSLOT,
              label=u'\u5f00\u59cb', name=u'StartButtonInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(392, 72),
              size=wx.Size(80, 35), style=0)
        self.StartButtonInConfirmPassLot.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.StartButtonInConfirmPassLot.Bind(wx.EVT_BUTTON,
              self.OnStartButtonInConfirmPassLotButton,
              id=wxID_FRAME1STARTBUTTONINCONFIRMPASSLOT)

        self.ReConfButtonInConfirmPassLot = wx.Button(id=wxID_FRAME1RECONFBUTTONINCONFIRMPASSLOT,
              label=u'\u6e05\u9664\u914d\u7f6e',
              name=u'ReConfButtonInConfirmPassLot', parent=self.ConfirmPassLot,
              pos=wx.Point(392, 140), size=wx.Size(80, 35), style=0)
        self.ReConfButtonInConfirmPassLot.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.ReConfButtonInConfirmPassLot.Bind(wx.EVT_BUTTON,
              self.OnReConfButtonInConfirmPassLotButton,
              id=wxID_FRAME1RECONFBUTTONINCONFIRMPASSLOT)

        self.ExitButtonInConfirmPassLot = wx.Button(id=wxID_FRAME1EXITBUTTONINCONFIRMPASSLOT,
              label=u'\u9000\u51fa', name=u'ExitButtonInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(392, 200),
              size=wx.Size(80, 35), style=0)
        self.ExitButtonInConfirmPassLot.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ExitButtonInConfirmPassLot.Bind(wx.EVT_BUTTON,
              self.OnExitButtonInConfirmPassLotButton,
              id=wxID_FRAME1EXITBUTTONINCONFIRMPASSLOT)

        self.NoteStaticBoxInConfirmPassLot = wx.StaticBox(id=wxID_FRAME1NOTESTATICBOXINCONFIRMPASSLOT,
              label=u'Note:', name=u'NoteStaticBoxInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(24, 152),
              size=wx.Size(352, 100), style=0)
        self.NoteStaticBoxInConfirmPassLot.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.NoteStaticBoxInConfirmPassLot.SetForegroundColour(wx.Colour(253,
              47, 23))

        self.Note1StaticTextInConfirmPassLot = wx.StaticText(id=wxID_FRAME1NOTE1STATICTEXTINCONFIRMPASSLOT,
              label=u'    \u5f53\u4f60\u4f7f\u7528ConfirmPassLot\u529f\u80fd\u7684\u65f6\u5019\uff0c\u4f60\u5fc5\u987b\u786e\u8ba4\u6574\u4e2aLot',
              name=u'Note1StaticTextInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(50, 184),
              size=wx.Size(320, 14), style=0)
        self.Note1StaticTextInConfirmPassLot.SetForegroundColour(wx.Colour(0, 0,
              255))

        self.Note2StaticTextInConfirmPassLot = wx.StaticText(id=wxID_FRAME1NOTE2STATICTEXTINCONFIRMPASSLOT,
              label=u'\u5df2\u7ecf\u6d4b\u8bd5\u5b8c\u6210\uff0c\u800c\u4e14\u6ca1\u6709\u95ee\u9898\u3002\u4f7f\u7528\u5b8c\u8fd9\u4e2a\u529f\u80fd\u540e\uff0c\u5b83\u5c06\u538b\u7f29\u5b8c',
              name=u'Note2StaticTextInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(37, 208),
              size=wx.Size(336, 14), style=0)
        self.Note2StaticTextInConfirmPassLot.SetForegroundColour(wx.Colour(0, 0,
              255))

        self.Note3StaticTextInConfirmPassLot = wx.StaticText(id=wxID_FRAME1NOTE3STATICTEXTINCONFIRMPASSLOT,
              label=u'\u6574\u4e2aLot\u7684\u6240\u6709\u6570\u636e\uff0c\u5e76\u5220\u9664\u6240\u6709\u7684\u6570\u636e\uff01',
              name=u'Note3StaticTextInConfirmPassLot',
              parent=self.ConfirmPassLot, pos=wx.Point(40, 232),
              size=wx.Size(222, 14), style=0)
        self.Note3StaticTextInConfirmPassLot.SetForegroundColour(wx.Colour(0, 0,
              255))

        self.OpenHelpFileButtonInConfigration = wx.Button(id=wxID_FRAME1OPENHELPFILEBUTTONINCONFIGRATION,
              label=u'\u6253\u5f00', name=u'OpenHelpFileButtonInConfigration',
              parent=self.Configration, pos=wx.Point(368, 43), size=wx.Size(75,
              32), style=wx.DOUBLE_BORDER)
        self.OpenHelpFileButtonInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.OpenHelpFileButtonInConfigration.SetExtraStyle(2)
        self.OpenHelpFileButtonInConfigration.Bind(wx.EVT_BUTTON,
              self.OnOpenHelpFileButtonInConfigrationButton,
              id=wxID_FRAME1OPENHELPFILEBUTTONINCONFIGRATION)

        self.HelpFileStaticBoxInConfigration = wx.StaticBox(id=wxID_FRAME1HELPFILESTATICBOXINCONFIGRATION,
              label=u'', name=u'HelpFileStaticBoxInConfigration',
              parent=self.Configration, pos=wx.Point(352, -8), size=wx.Size(120,
              88), style=wx.NO_BORDER)
        self.HelpFileStaticBoxInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.HelpFileStaticBoxInConfigration.SetThemeEnabled(True)

        self.HelpFileStaticTextInConfigration = wx.StaticText(id=wxID_FRAME1HELPFILESTATICTEXTINCONFIGRATION,
              label=u'\u5e2e\u52a9\u6587\u4ef6\uff1a',
              name=u'HelpFileStaticTextInConfigration',
              parent=self.Configration, pos=wx.Point(364, 13), size=wx.Size(95,
              23), style=0)
        self.HelpFileStaticTextInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.TestDataPathSaticBoxInConfigration = wx.StaticBox(id=wxID_FRAME1TESTDATAPATHSATICBOXINCONFIGRATION,
              label=u'', name=u'TestDataPathSaticBoxInConfigration',
              parent=self.Configration, pos=wx.Point(8, -2), size=wx.Size(336,
              83), style=0)

        self._init_coll_notebook1_Pages(self.notebook1)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.MyInit()
    def MyInit(self):
        global TestDataPath
        global DeviceInData
        global VersionInData
        
        self.StartButtonInData.Disable()
        self.ReConfigButtonInData.Disable()
        self.StartButtonInMapData.Disable()
        self.ViewButtonInMapData.Disable()
        self.StartButtonInWaferMap.Disable()
        self.NextButtonInWaferMap.Disable()
        self.PreButtonInWaferMap.Disable()
        self.StartButtonInConfigration.Disable()
        self.ReConfigButtonInConfigration.Disable()
        self.DeviceChoiceInData.Clear()
        self.DeviceChoiceInMapData.Clear()
        self.DeviceChoiceInWaferMap.Clear()
        self.DeviceNameChoiceInModifyPassWafer.Clear()
        self.DeviceChoiceInConfirmPassLot.Clear()
        self.DeleteButtonInModifyPassWafer.Disable()
        self.ReConfButtonInModifyPassWafer.Disable()
        self.StartButtonInConfirmPassLot.Disable()
        self.ReConfButtonInConfirmPassLot.Disable()
        
        DeviceInData=[]
        
        ConfigPath=os.path.join(ProjectPath,"Config")
        os.chdir(ConfigPath)
        
        InitiFile=open("InitSetting_Manual","r")
        for Line in InitiFile.readlines():
            if re.search(r'TestDataDir=',Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=',Line)
                TestDataDir=TempArray[1] 
                self.TestDataPathTextCtrlInCofigration.SetValue(TestDataDir)
            elif re.search(r'Device=',Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=|,',Line)
                self.DeviceChoiceInData.Append(TempArray[1])
                self.DeviceChoiceInMapData.Append(TempArray[1])
                self.DeviceChoiceInWaferMap.Append(TempArray[1])
                self.DeviceNameChoiceInModifyPassWafer.Append(TempArray[1])
                self.DeviceChoiceInConfirmPassLot.Append(TempArray[1])
            elif re.search(r'Resp=',Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=|,',Line)
                self.RespChoiceInConfirmPassLot.Append(TempArray[1])
        InitiFile.close
        
    def OnDeviceChoiceInDataChoice(self, event):
        
        global DeviceInData
        global FlagDevice
        global FlagLotNum
        #global FlagSortType
        global FlagWaferId
        global FlagVersion
        
        DeviceInData=event.GetString()
        ConfigPath=os.path.join(ProjectPath,"Config")
        os.chdir(ConfigPath)
        
        InitiFile=open("InitSetting_Manual","r")
        self.VersionChoiceInData.Clear()
        for Line in InitiFile.readlines():
            if re.search(DeviceInData,Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=|,',Line)
                #TestDataDir=TempArray[1] 
                for Index in range(3,len(TempArray)):
                    self.VersionChoiceInData.Append(TempArray[Index])
                    
        #    elif re.search(r'Device=',Line,re.I):
        #        Line=Line.strip()
        #        TempArray=re.split(r'=|,',Line)
        #        DeviceInData.append(TempArray[1])
        #        VersionInData[TempArray[1]]=TempArray[3]
        #self.DeviceChoiceInData.SetValue(DeviceInData)        
        InitiFile.close      
        if DeviceInData=="":
            FlagDevice=False
        else:
            FlagDevice=True
        
        if FlagDevice and FlagVersion and FlagLotNum  and FlagWaferId:
            self.StartButtonInData.Enable()
            self.ReConfigButtonInData.Enable()
            self.ExitButtonInData.Enable()
        else:
            self.StartButtonInData.Disable()
            
        #print DeviceInData,"FlagDevice:",FlagDevice

    def OnVersionChoiceInDataChoice(self, event):
        global VersionInData
        global FlagDevice
        global FlagLotNum
        #global FlagSortType
        global FlagWaferId
        global FlagVersion
        
        VersionInData=event.GetString()
        if VersionInData=="":
            FlagVersion=False
        else:
            FlagVersion=True
        
        if FlagDevice and FlagVersion and FlagLotNum  and FlagWaferId:
            self.StartButtonInData.Enable()
            self.ReConfigButtonInData.Enable()
            self.ExitButtonInData.Enable()
        else:
            self.StartButtonInData.Disable()    
        #print VersionInData,"FlagVersion:",FlagVersion

    def OnLotNoTextCtrlInDataText(self, event):
        global LotNumInData
        global FlagDevice
        global FlagLotNum
        #global FlagSortType
        global FlagWaferId
        global FlagVersion
        
        LotNumInData =event.GetString()
        if LotNumInData=="":
            FlagLotNum=False
        else:
            FlagLotNum=True
        
        if FlagDevice and FlagVersion and FlagLotNum  and FlagWaferId:
            self.StartButtonInData.Enable()
            self.ReConfigButtonInData.Enable()
            self.ExitButtonInData.Enable()
        else:
            self.StartButtonInData.Disable()   
        #print LotNumInData,"FlagLotNum:",FlagLotNum

    def OnLotNoButtonInDataButton(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global LotNumInData
            #TempArray=re.split(r"\\",dlg.GetPath())
            #LotNumInData=TempArray[len(TempArray)-1]
            LotNumInData=os.path.basename(dlg.GetPath())
            self.LotNoTextCtrlInData.SetValue(LotNumInData)
            #print LotNumInData 
            #print len(TempArray)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()

    def OnWaferNoTextCtrlInDataText(self, event):    
        global WaferIDInData
        global FlagDevice
        global FlagLotNum
        #global FlagSortType
        global FlagWaferId
        global FlagVersion
        
        WaferIDInData=""
        TempData=event.GetString()
        if TempData == "":
            dlg = wx.MessageDialog(self, 'The WaferID must not be empty In MapData!\n The format is 01;02;...', wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
                        
        TempArray=re.split(r";",TempData)
        TempFlag=0
        for Temp in TempArray:
            if re.search("\D+",Temp,re.I):
                if not re.search("~",Temp,re.I):
                    TempFlag=1
                    continue
            elif len(Temp)>0:
                if int(Temp)>25:
                    TempFlag=2
            else:
                TempArray.remove(Temp)
                if TempFlag==1:
                    dlg = wx.MessageDialog(self, 'There is some no digital in WaferID string In Data! ','A Error Box',wx.OK | wx.ICON_INFORMATION)
                    dlg.ShowModal()
                    dlg.Destroy()
                elif TempFlag==2:
                    dlg = wx.MessageDialog(self, 'There is some wrong waferID(That is more than 25 In Data!','A Error Box',wx.OK | wx.ICON_INFORMATION)
                    dlg.ShowModal()
                    dlg.Destroy() 
                        
                WaferIDInData=TempArray
                if len(WaferIDInData)<1:
                    FlagWaferId=False
                else:
                    FlagWaferId=True
                if FlagDevice and FlagVersion and FlagLotNum  and FlagWaferId:
                    self.StartButtonInData.Enable()
                    self.ReConfigButtonInData.Enable()
                    self.ExitButtonInData.Enable()
                else:
                    self.StartButtonInData.Disable()
                    
                print WaferIDInData,"FlagWaferId:",FlagWaferId

    def OnStartButtonInDataButton(self, event):
        
        self.StartButtonInData.Disable()
        self.ReConfigButtonInData.Disable()
        self.ExitButtonInData.Disable()
        global DeviceInData 
        global SortTypesInData
        global LotNumInData
        global WaferIDInData
        global TestDataDir
        global VersionInData
        global TestDataDir
        
        WaferIds=[]
        for Temp in WaferIDInData:
            if re.search("~",Temp,re.I):
                MyTemp=re.split("~",Temp,re.I)
                Min,Max=min(int(MyTemp[0]),int(MyTemp[1])),max(int(MyTemp[0]),int(MyTemp[1]))
                for Num in range(int(Min),int(Max)+1):
                    if not str(Num) in WaferIds:
                        WaferIds.append(str(Num))
            elif Temp.isdigit():
                WaferIds.append(Temp) 
        
        WaferIDInData=WaferIds
        
        #Device=DeviceInData    
        if DeviceInData=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The DeviceNmae must not be empty In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        if WaferIDInData=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The WaferId must not be empty In Data!\n Maybe the format is not right!the right format is 01;02;... ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        
        elif LotNumInData=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The LotNum must not be empty In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        elif TestDataDir=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The TestData Path is not confige In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        
        try:
            os.chdir(TestDataDir)
        
        except OSError:
            msg="".join((r"The TestDataPath:\"",TestDataDir,"\"isn't exist!When Using Manual Convert Data Tool."))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        DeviceVersion="".join((DeviceInData,"_",VersionInData))    
        LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInData)
        try:
            os.chdir(LotPath)
        
        except OSError:
            msg="".join((r"The Lot directory:",LotPath,"isn't exist!When Using Manual Convert Data Tool."))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        
        else:
            self.RunDataProcess(DeviceInData,SortTypesInData,LotNumInData,WaferIDInData,TestDataDir,VersionInData)
            #ProcessShowThread=self.MyThread(self.ProcessShow(len(WaferIDInData)))
            #self.GaugeInData.SetValue(1)
            #RunDataProcessThread=self.MyThread(self.RunDataProcess(DeviceInData,SortTypesInData,LotNumInData,WaferIDInData,TestDataDir,VersionInData))
            #ProcessShowThread.start()
            #RunDataProcessThread.start()
            #self.ProcessShow(len(WaferIDInData))  
            #CurrentPath=os.getcwd()
            #self.RunDataProcess(DeviceInData,SortTypesInData,LotNumInData,WaferIDInData,TestDataDir,VersionInData)
        self.ReConfigButtonInData.Enable()
        self.ExitButtonInData.Enable()    
    def RunDataProcess(self,DeviceInData,SortTypesInData,LotNumInData,WaferIDInData,TestDataDir,VersionInData):            
            Device=DeviceInData 
            ConfigPath=os.path.join(ProjectPath,"Config")
            LogPath=os.path.join(ProjectPath,"Log")
            BinDefinePath=os.path.join(ProjectPath,"Parameter")
            TempPath=os.path.join(ProjectPath,"Tmp")
            if not os.path.isdir(TempPath):
                os.mkdir(TempPath)
            ##############################################
            #Initial file directory!
            #############################################

            TempFileBHTC=os.path.join(TempPath,"bhtc_manual")
            TempOrgFileBHTC=os.path.join(TempPath,"orgbhtc")
            ErrorLogFile=os.path.join(LogPath,"error.log")
            ConfigureFile=os.path.join(ConfigPath,"config_NewUi")
                
            ##################################################
            #Start enter lot that need to manual convert lot
            ##################################################
            DeviceVersion="".join((Device,"_",VersionInData))
            LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInData)
            DataPath=os.path.join(LotPath,"Data") 
            RetestDataPath=os.path.join(LotPath,"Retest")        
            TimeConvert=time.asctime()
            #self.GaugeInData.SetValue(2)
            GaugeCount=0
            
            for WaferId in WaferIDInData:
                for SortType in [SortTypesInData]:                    
                    WaferFile=""
                    ##################################################
                    #Start new wafer that don't converted!
                    ##################################################
                    if re.search("_",LotNumInData,re.I):
                        TempArrayDatas=re.split("_",LotNumInData,re.I)
                        LotWaferId="".join((TempArrayDatas[0],"-",str(WaferId)))
                    else:
                        LotWaferId="".join((LotNumInData,"-",str(WaferId)))
                    Version=""
                    Patch=""
                    TesterName=""
                    OperatorName=""
                    ChannelMap=""
                    Title=""
                    StarTime=""
                    TestItemNum=""
                    DigitalTestItemNum=""
                    TestItemName=""
                    FileBHTC=""
                    RetestDataFiles=[]
                    FlagRetest=False
                    FlagRetestDataFileExist=False
                    FlagExisitBHTC=False
                    FlagExisitWaferFile=False
                    FlagTest="data"
                    FlagConfig=False
                    #FlagData=False
                    FlagRun=0
                    TimeConvert=time.asctime()
                    #print TimeConvert
                    TempLotWaferId=re.split("-",LotWaferId)
                    LotNum=TempLotWaferId[0]
                    WaferId=int(TempLotWaferId[1])
                    if len(TempLotWaferId[1])<2:
                        LotWaferId="".join((TempLotWaferId[0],"-","0",TempLotWaferId[1]))
                                
                    ######################################################
                    #Got all configure parameter from configure file
                    ######################################################
                    (FlagConfig,Version,Patch,TestItemNum,DigitalTestItemNum,TestItemNames)=Config(Device,SortType,ConfigPath,ConfigureFile)
                    
                    ##############################################################
                    #Find WaferFile In Data directory only for Manual Converting 
                    
                    try:
                        os.chdir(DataPath)
                    except OSError:
                        msg="".join((r"The TestDataPath:\"",DataPath,"\"isn't exist!When Using Manual Convert Data Tool."))
                        dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
                        dlg.ShowModal()
                        dlg.Destroy()
                    
                    else:    
                        ###############################################
                        #For Old UI because the file format is txt
                        ###############################################
                        os.chdir(DataPath)
                        #if len(glob.glob("*.txt")):
                        #    Rename(DataPath,"txt","data")
                        TempFiles=glob.glob("*.data")
                        for TempFile in TempFiles:
                            TempArrayDatas=re.split("_",TempFile)
                            Temp=re.split("-",TempArrayDatas[4])
                            if (re.search(LotNum,TempFile,re.I))and (WaferId ==int(Temp[1]))and (string.upper(SortType) == string.upper(TempArrayDatas[3])) :
                                WaferFile=TempFile
                                FlagExisitWaferFile=True
                                break           
                        if not FlagExisitWaferFile:
                            ZipFileName="".join((Device,"_",VersionInData,"_",os.path.basename(LotPath),"_",SortType,"_",FlagTest,".zip"))
                            if os.path.isfile(ZipFileName):
                                FileName=zipfile.ZipFile(ZipFileName,"r")
                                for TempFile in FileName.namelist():
                                    TempArrayDatas=re.split("_",TempFile)
                                    Temp=re.split("-",TempArrayDatas[4])
                                    if (re.search(LotNum,TempFile,re.I))and (WaferId ==int(Temp[1]))and (string.upper(SortType) == string.upper(TempArrayDatas[3])) :                   
                                        WaferFile=TempFile
                                        WaferFileFH=open(WaferFile,"w")
                                        WaferFileFH.write(FileName.read(WaferFile))
                                        WaferFileFH.close()
                                        FlagExisitWaferFile=True
                                        break
                                FileName.close()
                                
                                    
                        if FlagExisitWaferFile:                       
                            if FlagConfig:
                                GaugeCount=GaugeCount+float(3)/len(WaferIDInData)
                                self.GaugeInData.SetValue(GaugeCount)
                                ##################################
                                #Delete Temp bhtc File if exists
                                ##################################
                                if os.path.isfile(TempFileBHTC):
                                    os.unlink(TempFileBHTC)
                                if os.path.isdir(RetestDataPath):
                                    os.chdir(RetestDataPath)
                                    ZipFileName="".join((Device,"_",VersionInData,"_",os.path.basename(LotPath),"_",SortType,"_","Retest",".zip"))
                                    if os.path.isfile(ZipFileName):
                                        FileName=zipfile.ZipFile(ZipFileName,"r")
                                        for TempFile in FileName.namelist():
                                            TempArrayDatas=re.split("_",TempFile)
                                            Temp=re.split("-",TempArrayDatas[4])
                                            if string.upper(SortType)==string.upper("Sort1"):
                                                if (re.search(LotNum,TempFile,re.I))and (WaferId ==int(Temp[1]))and (string.upper(SortType) == string.upper(TempArrayDatas[3])) :                   
                                                    RetestDataFile=TempFile
                                                    RetestDataFileFH=open(RetestDataFile,"w")
                                                    RetestDataFileFH.write(FileName.read(RetestDataFile))
                                                    RetestDataFileFH.close()                                                   
                                                    
                                            else:
                                                if(re.search(LotNum,TempFile,re.I))and (WaferId ==int(Temp[1]))and (string.upper("Sort0")== string.upper(TempArrayDatas[3]) or string.upper(SortType) == string.upper(TempArrayDatas[3])) :                   
                                                    RetestDataFile=TempFile
                                                    RetestDataFileFH=open(RetestDataFile,"w")
                                                    RetestDataFileFH.write(FileName.read(RetestDataFile))
                                                    RetestDataFileFH.close()
                                                    
                                                    
                                        FileName.close()
                                    
                                    GaugeCount=GaugeCount+float(1)/len(WaferIDInData)
                                    self.GaugeInData.SetValue(GaugeCount)
                                    
                                    ###############################################
                                    #For Old UI because the file format is txt
                                    ###############################################
                                    #if len(glob.glob("*.txt")):
                                    #  Rename(RetestDataPath,"txt","data")
                                    TempRetestDataFiles=glob.glob("*.data")
                                    TempFiles=glob.glob("*.data")
                                    Date=[]
                                    Time=[]
                                    RetestDataFileNum=0
                                    ###################################################
                                    #Find the all retest file of the related wafer
                                    #and sort the retest files by tested time
                                    ###################################################
                                    
                                    for TempRetestDataFile in TempFiles:
                                        TempArrayDatas=re.split("_",TempRetestDataFile)
                                        Temp=re.split("-",TempArrayDatas[4])
                                        ReSortType="Sort0"                  
                                        if (re.search(LotNum,TempRetestDataFile,re.I))and (WaferId ==int(Temp[1]))and (string.upper(SortType) == string.upper(TempArrayDatas[3]) or string.upper(ReSortType)==string.upper(TempArrayDatas[3])) :
                                            TempDatas=re.split(r"_|\.",TempRetestDataFile)
                                            Date.append(TempDatas[5])
                                            Time.append(TempDatas[6])
                                            RetestDataFileNum=RetestDataFileNum+1
                                            FlagRetest=True
                                        else:
                                            TempRetestDataFiles.remove(TempRetestDataFile)
                                    TempDate=""
                                    TempTime=""
                                    GaugeCount=GaugeCount+float(1)/len(WaferIDInData)
                                    self.GaugeInData.SetValue(GaugeCount)
                                    for Index1 in range(RetestDataFileNum):
                                        for Index2 in range(RetestDataFileNum):                            
                                            if int(Date[Index1])<int(Date[Index2]):
                                                TempDate=Date[Index2]
                                                TempTime=Time[Index2]
                                                Date[Index2]=Date[Index1]
                                                Time[Index2]=Time[Index1]
                                                Date[Index1]=TempDate
                                                Time[Index1]=TempTime
                                            elif int(Date[Index1])<int(Date[Index2]):  
                                                if int(Time[Index1])<int(Time[Index2]):
                                                    TempDate=Date[Index2]
                                                    TempTime=Time[Index2]
                                                    Date[Index2]=Date[Index1]
                                                    Time[Index2]=Time[Index1]
                                                    Date[Index1]=TempDate
                                                    Time[Index1]=TempTime
                                    #RetestDataFiles=[] 
                                    
                                    GaugeCount=GaugeCount+float(1)/len(WaferIDInData)
                                    self.GaugeInData.SetValue(GaugeCount)
                                    
                                    for Index in range(RetestDataFileNum):                
                                        for TempFile in TempRetestDataFiles:                  
                                            if re.search(Date[Index],TempFile,re.I) and re.search(Time[Index],TempFile,re.I):
                                                RetestDataFiles.append(TempFile)
                                                TempRetestDataFiles.remove(TempFile)
                                GaugeCount=GaugeCount+float(1)/len(WaferIDInData)
                                self.GaugeInData.SetValue(GaugeCount)    
                                ######################################################
                                #Find if there is BHTC file when retest data exist
                                ######################################################
                                BHTCPath=os.path.join(LotPath,"bhtc")
                                    
                                if os.path.isdir(BHTCPath):
                                    os.chdir(BHTCPath)
                                    TempBHTCFiles=glob.glob("*.bhtc")
                                    for TempFile in TempBHTCFiles:
                                        TempArrayDatas=re.split("_|\.",TempFile)                  
                                        if re.search(LotNum,TempFile,re.I)and (WaferId==int(TempArrayDatas[-2]))and (SortType==TempArrayDatas[-3]):
                                            shutil.copyfile(TempFile,TempFileBHTC)                      
                                            FileBHTC=os.path.join(BHTCPath,TempFile)
                                            FlagExisitBHTC=True
                                            break
                                
                                GaugeCount=GaugeCount+float(2)/len(WaferIDInData)
                                self.GaugeInData.SetValue(GaugeCount)
                                #########################################
                                #Covert data
                                #########################################
                                if FlagExisitBHTC and FlagRetest:
                                    shutil.move(FileBHTC,TempOrgFileBHTC)
                                
                                if os.path.isfile(FileBHTC):
                                    os.unlink(FileBHTC)
                                (FlagRun,StarTime,ProgramName,TesterName,Operator,ChannelMap)=NewUiData2BHTC(LotPath,WaferFile,TempFileBHTC,TestItemNum,TestItemNames,DigitalTestItemNum,FlagTest)  
                                ###############################################
                                #Zip the converted data file 
                                ###############################################
                                GaugeCount=GaugeCount+float(25)/len(WaferIDInData)
                                self.GaugeInData.SetValue(GaugeCount)
                                if not FlagRun:
                                    os.chdir(os.path.join(LotPath,FlagTest))
                                    if re.search("Sort1",SortType,re.I):
                                        ZipFileName="".join((Device,"_",Version,"_",os.path.basename(LotPath),"_",SortType,"_",FlagTest,".zip"))
                                        self.MyZipFile(ZipFileName,WaferFile,True)
                                    if re.search("Sort2",SortType,re.I) or re.search("Sort0",SortType,re.I):
                                        ZipFileName="".join((Device,"_",Version,"_",os.path.basename(LotPath),"_","Sort2","_",FlagTest,".zip"))
                                        self.MyZipFile(ZipFileName,WaferFile,True)
                                        
                                if FlagRetest:
                                    TempFlagRun=0
                                    TempFlag=0
                                    FlagTest="Retest"
                                    for RetestDataFile in RetestDataFiles:
                                        TempDataFileName=re.split(r"_",RetestDataFile)
                                        DeviceName=TempDataFileName[0]          
                                        SortType=TempDataFileName[3]
                                        #LotWaferId=TempDataFileName[4]
                                        (FlagConfig,Version,Patch,TestItemNum,DigitalTestItemNum,TestItemNames)=Config(DeviceName,SortType,ConfigPath,ConfigureFile)                  
                                        
                                        GaugeCount=GaugeCount+float(6)/len(WaferIDInData)
                                        self.GaugeInData.SetValue(GaugeCount)
                                        
                                        if string.upper(SortType)==string.upper("Sort0"):
                                            SortType="Sort2"
                                        (TempFlag,ProgramName,TesterName,Operator,ChannelMap)=NewUiData2BHTC(LotPath,RetestDataFile,TempFileBHTC,TestItemNum,TestItemNames,DigitalTestItemNum,FlagTest)  
                                        GaugeCount=GaugeCount+float(20)/len(WaferIDInData)
                                        self.GaugeInData.SetValue(GaugeCount)
                                        
                                        ###############################################
                                        #Zip the converted retest data file 
                                        ###############################################
                                        os.chdir(os.path.join(LotPath,FlagTest))
                                        if re.search("Sort1",SortType,re.I):
                                            ZipFileName="".join((Device,"_",Version,"_",os.path.basename(LotPath),"_",SortType,"_",FlagTest,".zip"))
                                            self.MyZipFile(ZipFileName,RetestDataFile,True)
                                        if re.search("Sort2",SortType,re.I) or re.search("Sort0",SortType,re.I):
                                            ZipFileName="".join((Device,"_",Version,"_",os.path.basename(LotPath),"_","Sort2","_",FlagTest,".zip"))
                                            self.MyZipFile(ZipFileName,RetestDataFile,True)
                                        TempFlagRun=TempFlagRun or TempFlag
                                        GaugeCount=GaugeCount+float(10)/len(WaferIDInData)
                                        self.GaugeInData.SetValue(GaugeCount)
                                    if TempFlagRun:
                                        FlagRun=TempFlagRun
                                GaugeCount=GaugeCount+float(10)/len(WaferIDInData)
                                self.GaugeInData.SetValue(GaugeCount)
                                ###########################################
                                #Print out the related customer data
                                ###########################################
                                if not FlagRun:                                    
                                    GaugeCount=GaugeCount+float(2)/len(WaferIDInData)
                                    self.GaugeInData.SetValue(GaugeCount)
                                    FlagRun=BHTC2CustData(LotPath,Device,TestItemNum,TesterName,ProgramName,Version,LotWaferId,Patch,SortType,Operator,ChannelMap,StarTime,BinDefinePath,TempFileBHTC,Title)
                                    PassWaferLogFH=open(os.path.join(LogPath,"passwafer.log"),"a")
                                    PassWaferLogFH.write("%26s%5s%15s%5s%20s%5s%18s%5s%12s%5s" %(TimeConvert,"|",Device,"|",LotNumInData,"|",LotWaferId,"|",SortType,"\n"))
                                    PassWaferLogFH.close()
    
                                    GaugeCount=GaugeCount+float(30)/len(WaferIDInData)
                                    self.GaugeInData.SetValue(GaugeCount)
                            else:
                                ErrorFH=open(ErrorLogFile,"a")
                                ErrorFH.write(TimeConvert),
                                ErrorFH.write("\tNot found device:"),
                                ErrorFH.write(Device),
                                ErrorFH.write("\'s configure data in file:"),
                                ErrorFH.write(ConfigureFile),
                                ErrorFH.write("! When Converting File:")
                                ErrorFH.write(WaferFile)
                                ErrorFH.write("\n")
                                ErrorFH.close()
                                dlg = wx.MessageDialog(self, r'The Device configue data can not be found in configruation file In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
                                dlg.ShowModal()
                                dlg.Destroy()
                                    #TempTime=time.asctime()
                                    #print TempTime
                        else:
                            Msg="".join(("Wafer:",str(WaferId)," SortType:",str(SortType),r'The First Test Data file can not be found in Data directory In Data! '))
                            dlg = wx.MessageDialog(self,Msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
                            dlg.ShowModal()
                            dlg.Destroy()
                
            self.StartButtonInData.Enable()
            self.ReConfigButtonInData.Enable()
            self.ExitButtonInData.Enable()
            self.GaugeInData.SetValue(100)
                                        
    def OnReConfigButtonInDataButton(self, event):
        global WaferIDInData
        global SortTypesInData
        global LotNumInData
        global DeviceNameInData
                
        self.WaferNoTextCtrlInData.SetValue("01;")
        WaferIDInData="01;"
                
        self.SortTypeRadioBoxInData.SetSelection(0)
        SortTypesInData=["Sort1"]
                
        self.LotNoTextCtrlInData.SetValue("")        
        LotNumInData=""
                
        self.DeviceChoiceInData.SetSelection(-1)
        DeviceInData=""
        self.VersionChoiceInData.SetSelection(-1)
        VersionInData=""

    def OnExitButtonInDataButton(self, event):
        sys.exit()
    def OnTestDataPathTextCtrlInCofigrationText(self, event):
        global TestDataDir
        if event.GetString()=="":
            dlg = wx.MessageDialog(self, 'The TestDataDir must not be empty In configration!','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()   
        else:
            TestDataDir=event.GetString()
            
        #print TestDataDir

    def OnTestDataPathButtonInConfigrationButton(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global TestDataDir            
            TestDataDir=dlg.GetPath()
            self.TestDataPathTextCtrlInCofigration.SetValue(TestDataDir)
            ConfigPath=os.path.join(ProjectPath,"Config")
            os.chdir(ConfigPath)
            InitFile = open("InitSetting_Manual","r+")
            InitFileOut= open("InitSetting_ManualOut","w")
            for Line in InitFile.readlines():
                if re.search(r'TestDataDir=',Line,re.I):
                    InitFileOut.write("TestDataDir=%s\n" % TestDataDir)
                else :
                    InitFileOut.write(Line)
            InitFile.close
            InitFileOut.close
            del InitFile
            del InitFileOut
            os.unlink("InitSetting_Manual")            
            shutil.move("InitSetting_ManualOut","InitSetting_Manual")   
                
            #print LotNum 
            #print len(TempArray)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()



    def OnSortTypeRadioBoxInDataRadiobox(self, event):
        global SortTypesInData
        SortTypeSelect=event.GetInt()
        if SortTypeSelect==0:
            SortTypesInData="Sort1"
        elif SortTypeSelect==1:
            SortTypesInData="Sort2"         
                
        #print SortTypesInData  
    def ProcessShow(self,WaferNum):
        count=0
        for Index in range(100):
            time.sleep(float(8)/100*WaferNum)
            self.GaugeInData.SetValue(count)
            count = count + 1

    def OnDeviceChoiceInMapDataChoice(self, event):
        global DeviceInMapData
        global FlagDeviceInMap
        global FlagLotNumInMap
        #global FlagSortType       
        global FlagVersionInMap
        
        DeviceInMapData=event.GetString()
        ConfigPath=os.path.join(ProjectPath,"Config")
        os.chdir(ConfigPath)

        InitiFile=open("InitSetting_Manual","r")
        self.VersionChoiceInMapData.Clear()
        for Line in InitiFile.readlines():
            if re.search(DeviceInMapData,Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=|,',Line)
                #TestDataDir=TempArray[1] 
                for Index in range(3,len(TempArray)):
                    self.VersionChoiceInMapData.Append(TempArray[Index])
                    
        #    elif re.search(r'Device=',Line,re.I):
        #        Line=Line.strip()
        #        TempArray=re.split(r'=|,',Line)
        #        DeviceInData.append(TempArray[1])
        #        VersionInData[TempArray[1]]=TempArray[3]
        #self.DeviceChoiceInData.SetValue(DeviceInData)        
        InitiFile.close      
        if DeviceInMapData=="":
            FlagDeviceInMap=False
        else:
            FlagDeviceInMap=True
        
        if FlagDeviceInMap and FlagVersionInMap and FlagLotNumInMap :
            self.StartButtonInMapData.Enable()
            self.ViewButtonInMapData.Enable()
        else:
            self.StartButtonInMapData.Disable()
            self.ViewButtonInMapData.Disable()
        #print DeviceInMapData,"FlagDeviceInMap:",FlagDeviceInMap


    def OnLotNoTextCtrlInMapDataText(self, event):
        global LotNumInMapData
        global FlagDeviceInMap
        global FlagLotNumInMap
        global FlagVersionInMap
        
        LotNumInMapData =event.GetString()
        if LotNumInMapData=="":
            FlagLotNumInMap=False
        else:
            FlagLotNumInMap=True
        
        if FlagDeviceInMap and FlagVersionInMap and FlagLotNumInMap :
            self.StartButtonInMapData.Enable()
            self.ViewButtonInMapData.Enable()
        else:
            self.StartButtonInMapData.Disable()
            self.ViewButtonInMapData.Disable()
        #print LotNumInMapData,"FlagLotNumInMap:",FlagLotNumInMap

    def OnLotNoButtonInMapDataButton(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global LotNumInMapData
            #TempArray=re.split(r"\\",dlg.GetPath())
            #LotNumInData=TempArray[len(TempArray)-1]
            LotNumInMapData=os.path.basename(dlg.GetPath())
            self.LotNoTextCtrlInMapData.SetValue(LotNumInMapData)
            #print LotNumInMapData 
            #print len(TempArray)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()


    def OnSortTypeRadioBoxInMapDataRadiobox(self, event):
        global SortTypesInMapData
        SortTypeSelect=event.GetInt()
        if SortTypeSelect==0:
            SortTypesInMapData=["Sort1"]
        elif SortTypeSelect==1:
            SortTypesInMapData=["Sort2"]
        elif SortTypeSelect==2:
            SortTypesInMapData=["Sort1","Sort2"]    
        
            
                
        #print SortTypesInMapData 

    def OnStartButtonInMapDataButton(self, event):
        self.ViewButtonInMapData.Disable()
        self.StartButtonInMapData.Disable()
        self.ExitButtonInMapData.Disable()
        global DeviceInMapData 
        global SortTypesInMapData
        global LotNumInMapData
        global TestDataDir
        global VersionInMapData
        global TestDataDir
        
        #Device=DeviceInData    
        if DeviceInMapData=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The DeviceNmae must not be empty In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        elif LotNumInMapData=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The LotNum must not be empty In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        elif TestDataDir=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The TestData Path is not confige In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        
        try:
            os.chdir(TestDataDir)
        
        except OSError:
            msg="".join((r"The TestDataPath:\"",TestDataDir,"\"isn't exist!When Using Manual Convert Data Tool."))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        
        
        else:  
            self.RunConvertMapData(TestDataDir,DeviceInMapData,SortTypesInMapData,LotNumInMapData)
            self.StartButtonInMapData.Enable()
            self.ExitButtonInMapData.Enable()
            self.ViewButtonInMapData.Enable()
        

    def RunConvertMapData(self,TestDataDir,DeviceInMapData,SortTypesInMapData,LotNumInMapData): 
        DeviceVersion="".join((DeviceInMapData,"_",VersionInMapData))
        LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInMapData)
        MapDir=os.path.join(LotPath , "Map")
        ErrorMsg= "".join((r'The Direcotry: ',MapDir,r' is not exist InMapData!\n '))
        if not os.path.isdir(MapDir):                   
            dlg = wx.MessageDialog(self,ErrorMsg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        else :
            os.chdir(MapDir)
            files=glob.glob('*.map')
            
            FlagTempRun=False
            
            for SortType in SortTypesInMapData:
                #OutFileName=LotNumInMapData + "_" + SortType + "_" + "mapdata.txt"
                OutFileName="".join((LotNumInMapData , "_" ,SortType ,"_" ,"MapData.txt"))                
                
                OutFile=open(OutFileName,"w")
                TotalGoodDie=0
                for file in files:
                    PassDie=0                
                    if re.search(SortType,file,re.I):
                        FlagTempRun=True
                        MapFile=open(file)
                        Lines=MapFile.readlines()
                        for Line in Lines:
                            if re.search("\s+\d+\s+[\d+|\w+|\+]\s+\d+\s+\d+\.\d+%\s+PASS;",Line,re.I):
                                TempDatas=re.split("\s+",Line)
                                PassDie=int(TempDatas[3])                        
                                TotalGoodDie=TotalGoodDie+PassDie
                            
                        OutFile.write("%s : %d\n" % (file,PassDie))
                OutFile.write("Total Passed:  %d\n" % TotalGoodDie)
                OutFile.close
            if not FlagTempRun:
                ErrorMsg="".join(("Not find Device:",DeviceInMapData," ",SortType," Map File!"))
                dlg = wx.MessageDialog(self,ErrorMsg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                
                
    def OnViewButtonInMapDataButton(self, event):
            
        global DeviceInMapData 
        global SortTypesInMapData
        global LotNumInMapData
        global TestDataDir
        global VersionInMapData
        
        self.StartButtonInMapData.Disable()
        self.ExitButtonInMapData.Disable()
        self.ViewButtonInMapData.Disable()
        
                
                
        #Device=DeviceInData    
        if DeviceInMapData=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The DeviceNmae must not be empty In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        elif LotNumInMapData=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The LotNum must not be empty In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        elif TestDataDir=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The TestData Path is not confige In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        
        else:  
            DeviceVersion="".join((DeviceInMapData,"_",VersionInMapData))
            LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInMapData)
            MapDir=os.path.join(LotPath , "Map")
            ErrorMsg= "".join((r'The Direcotry: ',MapDir,r' is not exist InMapData!\n '))
            if not os.path.isdir(MapDir):                   
                dlg = wx.MessageDialog(self,ErrorMsg ,'A Error Box',wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
            else :
                os.chdir(MapDir)            
                for SortType in SortTypesInMapData:
                    #OutFileName=LotNumInMapData + "_" + SortType + "_" + "mapdata.txt"
                    MapDataFileName="".join((LotNumInMapData , "_" ,SortType ,"_" ,"MapData.txt"))
                    if os.path.isfile(MapDataFileName):
                        MapDataFileNameFH=open(MapDataFileName,"r")
                        msg=""
                        for Line in MapDataFileNameFH.readlines():
                            msg="".join((msg,Line))
                        MapDataFileNameFH.close()
                        dlg = wx.lib.dialogs.ScrolledMessageDialog(self, msg, "message test")
                        dlg.ShowModal()
                    else:
                        ErrorMsg= "".join((DeviceInMapData," ",SortType,r' MapData is not exist!\n You can convert it at first!\n '))
                        dlg = wx.MessageDialog(self,ErrorMsg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
                        dlg.ShowModal()
                        dlg.Destroy()
        self.StartButtonInMapData.Enable()
        self.ExitButtonInMapData.Enable()
        self.ViewButtonInMapData.Enable()
    def OnExitButtonInMapDataButton(self, event):
        sys.exit()

    def OnVersionChoiceInMapDataChoice(self, event):
        global VersionInMapData
        global FlagDeviceInMap
        global FlagLotNumInMap
        global FlagVersionInMap
        
        VersionInMapData=event.GetString()
        if VersionInMapData=="":
            FlagVersionInMap=False
        else:
            FlagVersionInMap=True
        
        if FlagDeviceInMap and FlagVersionInMap and FlagLotNumInMap :
            self.StartButtonInMapData.Enable()
        else:
            self.StartButtonInMapData.Disable()    
        #print VersionInMapData,"FlagVersionInMap:",FlagVersionInMap
    
    def MyZipFile(self,ZipFileName,FileName,FlagDelFile):
        if not os.path.isfile(ZipFileName):
            FileNameFH=zipfile.ZipFile(ZipFileName,"w")
            FileNameFH.write(FileName,None,zipfile.ZIP_DEFLATED)
            FileNameFH.close()
            
        else:
            FlagFileExist=False
            FileNameFH=zipfile.ZipFile(ZipFileName,"r")
            for TempFileName in FileNameFH.namelist():
                if re.search(FileName,TempFileName,re.I):
                    FlagFileExist=True
                    break
            FileNameFH.close()
            if not FlagFileExist:    
                FileNameFH=zipfile.ZipFile(ZipFileName,"a")
                FileNameFH.write(FileName,None,zipfile.ZIP_DEFLATED)
                FileNameFH.close()
        if FlagDelFile:
            os.unlink(FileName)

    def OnDeviceChoiceInWaferMapChoice(self, event):
        global DeviceInWaferMap
        global FlagDeviceInWaferMap
        global FlagLotNumInWaferMap
        #global FlagSortType       
        global FlagVersionInWaferMap
        global FlagWaferIdInWaferMap
        
        DeviceInWaferMap=event.GetString()
        ConfigPath=os.path.join(ProjectPath,"Config")
        os.chdir(ConfigPath)

        InitiFile=open("InitSetting_Manual","r")
        self.VersionChoiceInWaferMap.Clear()
        for Line in InitiFile.readlines():
            if re.search(DeviceInWaferMap,Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=|,',Line)
                #TestDataDir=TempArray[1] 
                for Index in range(3,len(TempArray)):
                    self.VersionChoiceInWaferMap.Append(TempArray[Index])
                    
        #    elif re.search(r'Device=',Line,re.I):
        #        Line=Line.strip()
        #        TempArray=re.split(r'=|,',Line)
        #        DeviceInData.append(TempArray[1])
        #        VersionInData[TempArray[1]]=TempArray[3]
        #self.DeviceChoiceInData.SetValue(DeviceInData)        
        InitiFile.close      
        if DeviceInWaferMap=="":
            FlagDeviceInWaferMap=False
        else:
            FlagDeviceInWaferMap=True
        
        if FlagDeviceInWaferMap and FlagVersionInWaferMap and FlagLotNumInWaferMap and FlagWaferIdInWaferMap :
            self.StartButtonInWaferMap.Enable()
            
        else:
            self.StartButtonInWaferMap.Disable()
            self.NextButtonInWaferMap.Disable()
            self.PreButtonInWaferMap.Disable()
        #print DeviceInWaferMap,"FlagDeviceInMap:",FlagDeviceInWaferMap



    def OnVersionChoiceInWaferMapChoice(self, event):
        global VersionInWaferMap
        global FlagDeviceInWaferMap
        global FlagLotNumInWaferMap
        #global FlagSortType
        global FlagWaferIdInWaferMap
        global FlagVersionInWaferMap
        
        VersionInWaferMap=event.GetString()
        if VersionInWaferMap=="":
            FlagVersionInWaferMap=False
        else:
            FlagVersionInWaferMap=True
        
        if FlagDeviceInWaferMap and FlagVersionInWaferMap and FlagLotNumInWaferMap  and FlagWaferIdInWaferMap:
            self.StartButtonInWaferMap.Enable()
            
        else:
            self.StartButtonInWaferMap.Disable()
            self.StartButtonInWaferMap.Disable()
            self.NextButtonInWaferMap.Disable()
            self.PreButtonInWaferMap.Disable()
        #print VersionInWaferMap,"FlagVersionInWaferMap:",FlagVersionInWaferMap

    def OnLotNumTextCtrlInWaferMapText(self, event):
        global LotNumInWaferMap
        global FlagDeviceInWaferMap
        global FlagLotNumInWaferMap
        #global FlagSortType
        global FlagWaferIdInWaferMap
        global FlagVersionInWaferMap
        
        LotNumInWaferMap =event.GetString()
        if LotNumInWaferMap=="":
            FlagLotNumInWaferMap=False
        else:
            FlagLotNumInWaferMap=True
        
        if FlagDeviceInWaferMap and FlagVersionInWaferMap and FlagLotNumInWaferMap  and FlagWaferIdInWaferMap:
            self.StartButtonInWaferMap.Enable()
            
        else:
            self.StartButtonInWaferMap.Disable()
            self.StartButtonInWaferMap.Disable()
            self.NextButtonInWaferMap.Disable()
            self.PreButtonInWaferMap.Disable()
        #print LotNumInWaferMap,"FlagLotNumInWaferMap:",FlagLotNumInWaferMap

    def OnWaferNoTextCtrlInWaferMapText(self, event):
        global WaferIdInWaferMap
        global FlagDeviceInWaferMap
        global FlagLotNumInWaferMap
        #global FlagSortType
        global FlagWaferIdInWaferMap
        global FlagVersionInWaferMap
        
        WaferIDInWaferMap=""
        TempData=event.GetString()
        if TempData == "":
            dlg = wx.MessageDialog(self, 'The WaferID must not be empty In MapData!\n The format is 01;02;...','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
                        
        TempArray=re.split(r";",TempData)
        TempFlag=0
        for Temp in TempArray:
            if re.search("\D+",Temp,re.I):
                if not re.search("~",Temp,re.I):
                    TempFlag=1
                    continue                
            elif len(Temp)>0:
                if int(Temp)>25:
                    TempFlag=2
            else:
                TempArray.remove(Temp) 
                if TempFlag==1:
                    dlg = wx.MessageDialog(self, 'There is some no digital in WaferID string In Data! ','A Error Box',wx.OK | wx.ICON_INFORMATION)
                    dlg.ShowModal()
                    dlg.Destroy()
                elif TempFlag==2:
                    dlg = wx.MessageDialog(self, 'There is some wrong waferID(That is more than 25 In Data!','A Error Box',wx.OK | wx.ICON_INFORMATION)
                    dlg.ShowModal()
                    dlg.Destroy() 
                        
                WaferIdInWaferMap=TempArray
                if len(WaferIdInWaferMap)<1:
                    FlagWaferIdInWaferMap=False
                else:
                    FlagWaferIdInWaferMap=True
                if FlagDeviceInWaferMap and FlagVersionInWaferMap and FlagLotNumInWaferMap  and FlagWaferIdInWaferMap:
                    self.StartButtonInWaferMap.Enable()
                    
                else:
                    self.StartButtonInWaferMap.Disable()
                    self.NextButtonInWaferMap.Disable()
                    self.PreButtonInWaferMap.Disable()
            #print WaferIdInWaferMap,"FlagWaferIdInWaferMap:",FlagWaferIdInWaferMap

    def OnLotNoButtonInWaferMapButton(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global LotNumInData
            #TempArray=re.split(r"\\",dlg.GetPath())
            #LotNumInData=TempArray[len(TempArray)-1]
            LotNumInData=os.path.basename(dlg.GetPath())
            self.LotNumTextCtrlInWaferMap.SetValue(LotNumInData)
            #print LotNumInData 
            #print len(TempArray)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()

    
    def OnSortTypeRadioBoxInWaferMapRadiobox(self, event):
        global SortTypesInWaferMap
        SortTypeSelect=event.GetInt()
        if SortTypeSelect==0:
            SortTypesInWaferMap="Sort1"
        elif SortTypeSelect==1:
            SortTypesInWaferMap="Sort2"  
        #print SortTypesInWaferMap
    def OnStartButtonInWaferMapButton(self, event):
        self.StartButtonInWaferMap.Disable()
        
        global DeviceInWaferMap
        global SortTypesInWaferMap
        global LotNumInWaferMap
        global WaferIdInWaferMap
        global TestDataDir
        global VersionInWaferMap
        global TestDataDir
        global IndexInWaferMap
        
        WaferIds=[]
        #TempArray=re.split(";",WaferIDInModifyPassWafer,re.I)
        for Temp in WaferIdInWaferMap:
            if re.search("~",Temp,re.I):
                MyTemp=re.split("~",Temp,re.I)
                Min,Max=min(int(MyTemp[0]),int(MyTemp[1])),max(int(MyTemp[0]),int(MyTemp[1]))
                for Num in range(int(Min),int(Max)+1):
                    if not str(Num) in WaferIds:
                        WaferIds.append(str(Num))
            elif Temp.isdigit():
                WaferIds.append(Temp) 
                
        WaferIdInWaferMap=WaferIds
        #Device=DeviceInData    
        if DeviceInWaferMap=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The DeviceNmae must not be empty In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        if WaferIdInWaferMap=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The WaferId must not be empty In Data!\n Maybe the format is not right!the right format is 01;02;... ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        
        elif LotNumInWaferMap=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The LotNum must not be empty In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        elif TestDataDir=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The TestData Path is not confige In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        
        try:
            os.chdir(TestDataDir)
        
        except OSError:
            msg="".join((r"The TestDataPath:\"",TestDataDir,"\"isn't exist!When Using Manual Convert Data Tool."))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        DeviceVersion="".join((DeviceInWaferMap,"_",VersionInWaferMap))    
        LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInWaferMap)
        try:
            os.chdir(LotPath)
        
        except OSError:
            msg="".join((r"The Lot directory:",LotPath,"isn't exist!When Using Manual Convert Data Tool."))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        
        else:
            DeviceVersion="".join((DeviceInWaferMap,"_",VersionInWaferMap))
            LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInWaferMap)
            if len(WaferIdInWaferMap)>1:
                self.NextButtonInWaferMap.Enable()
                self.PreButtonInWaferMap.Enable()
            WaferMapFrame=MyWaferMapFrame(None,u"WaferMap Display",LotPath,WaferIdInWaferMap[0],SortTypesInWaferMap)
            WaferMapFrame.Show(True)
            self.StartButtonInWaferMap.Enable()
            IndexInWaferMap=0
        

    def OnNextButtonInWaferMapButton(self, event):
        global IndexInWaferMap
        global WaferIdInWaferMap
        global DeviceInWaferMap
        global SortTypesInWaferMap
        global LotNumInWaferMap
        global WaferIdInWaferMap
        global TestDataDir
        global VersionInWaferMap
        global TestDataDir
        DeviceVersion="".join((DeviceInWaferMap,"_",VersionInWaferMap))
        LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInWaferMap)
        IndexInWaferMap=IndexInWaferMap+1
        if IndexInWaferMap>1:
            self.PreButtonInWaferMap.Enable()
        if IndexInWaferMap==len(WaferIdInWaferMap)-1:
            self.NextButtonInWaferMap.Disable()    
        if 0<IndexInWaferMap<len(WaferIdInWaferMap):
            WaferMapFrame=MyWaferMapFrame(None,u"WaferMap Display",LotPath,WaferIdInWaferMap[IndexInWaferMap],SortTypesInWaferMap)
            WaferMapFrame.Show(True)
            self.StartButtonInWaferMap.Enable()
        

    def OnPreButtonInWaferMapButton(self, event):
        global IndexInWaferMap
        global WaferIdInWaferMap
        global DeviceInWaferMap
        global SortTypesInWaferMap
        global LotNumInWaferMap
        global WaferIdInWaferMap
        global TestDataDir
        global VersionInWaferMap
        global TestDataDir
        DeviceVersion="".join((DeviceInWaferMap,"_",VersionInWaferMap))
        LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInWaferMap)
        IndexInWaferMap=IndexInWaferMap-1
        if IndexInWaferMap==0:
            self.PreButtonInWaferMap.Disable()    
        if len(WaferIdInWaferMap)>IndexInWaferMap>=0:
            WaferMapFrame=MyWaferMapFrame(None,u"WaferMap Display",LotPath,WaferIdInWaferMap[IndexInWaferMap],SortTypesInWaferMap)
            WaferMapFrame.Show(True)
            self.StartButtonInWaferMap.Enable()

    def OnExitButtonInWaferMapButton(self, event):
        sys.exit()

    def OnDeviceNameTextCtrlInConfigrationText(self, event):
        global DeviceInConfigration
        global FlagDeviceInConfigration
        global FlagPathInConfigration
        global FlagTestDataInConfigration
        global FlagVersionInConfigration
                
        DeviceInConfigration =event.GetString()
        if DeviceInConfigration=="":
            FlagDeviceInConfigration=False
        else:
            FlagDeviceInConfigration=True
                
        if FlagDeviceInConfigration and FlagVersionInConfigration and FlagPathInConfigration  and FlagTestDataInConfigration:
            self.StartButtonInConfigration.Enable()
                    
        else:
            self.StartButtonInConfigration.Disable()
            
        #print DeviceInConfigration,"FlagDeviceInConfigration:",FlagDeviceInConfigration
        

    def OnDeviceVersionTextCtrlInConfigrationText(self, event):
        global VersionInConfigration
        global FlagDeviceInConfigration
        global FlagPathInConfigration
        global FlagTestDataInConfigration
        global FlagVersionInConfigration
        
        VersionInConfigration =event.GetString()
        if DeviceInConfigration=="":
            FlagVersionInConfigration=False
        else:
            FlagVersionInConfigration=True
        
        if FlagDeviceInConfigration and FlagVersionInConfigration and FlagPathInConfigration  and FlagTestDataInConfigration:
            self.StartButtonInConfigration.Enable()
            
        else:
            self.StartButtonInConfigration.Disable()
        
        if FlagDeviceInConfigration or FlagVersionInConfigration or FlagPathInConfigration  or FlagTestDataInConfigration:
            self.ReConfigButtonInConfigration.Enable()
        
        #print VersionInConfigration,"FlagVersionInConfigration:",FlagVersionInConfigration

    def OnSortTypeRadioBoxInConfigrationRadiobox(self, event):
        global SortTypesInConfigration
        SortTypeSelect=event.GetInt()
        if SortTypeSelect==0:
            SortTypesInConfigration="Sort0"
        elif SortTypeSelect==1:
            SortTypesInConfigration="Sort1"         
        elif SortTypeSelect==2:
            SortTypesInConfigration="Sort2" 
                
        #print SortTypesInConfigration  
        

    def OnPathTextCtrlInConfigrationText(self, event):
        global PathInConfigration
        global FlagDeviceInConfigration
        global FlagPathInConfigration
        global FlagTestDataInConfigration
        global FlagVersionInConfigration
        
        PathInConfigration =event.GetString()
        if PathInConfigration=="":
            FlagPathInConfigration=False
        if not PathInConfigration.isdigit():
            msg="".join((r"The Path: ",PathInConfigration,"is not digital you input. Runing Fail when you do device configuration!"))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        else:
            FlagPathInConfigration=True
            
        if FlagDeviceInConfigration and FlagVersionInConfigration and FlagPathInConfigration  and FlagTestDataInConfigration:
            self.StartButtonInConfigration.Enable()
            
        else:
            self.StartButtonInConfigration.Disable()
        
        if FlagDeviceInConfigration or FlagVersionInConfigration or FlagPathInConfigration  or FlagTestDataInConfigration:
            self.ReConfigButtonInConfigration.Enable()
        
        #print PathInConfigration,"FlagPathInConfigration:",FlagPathInConfigration
        

    def OnTestDataFileTextCtrlInConfigrationText(self, event):
        global TestDataFileInConfigration
        global FlagDeviceInConfigration
        global FlagPathInConfigration
        global FlagTestDataInConfigration
        global FlagVersionInConfigration
        
        TestDataFileInConfigration =event.GetString()
        if TestDataFileInConfigration=="":
            FlagTestDataInConfigration=False
        else:
            FlagTestDataInConfigration=True
        
        if FlagDeviceInConfigration and FlagVersionInConfigration and FlagPathInConfigration  and FlagTestDataInConfigration:
            self.StartButtonInConfigration.Enable()
            
        else:
            self.StartButtonInConfigration.Disable()
        
        if FlagDeviceInConfigration or FlagVersionInConfigration or FlagPathInConfigration  or FlagTestDataInConfigration:
            self.ReConfigButtonInConfigration.Enable()
        
        #print TestDataFileInConfigration,"FlagTestDataInConfigration:",FlagTestDataInConfigration
        

    def OnTestDataFileButtonInConfigrationButton(self, event):
        global TestDataDir
        os.chdir(TestDataDir)
        dlg = wx.FileDialog(
            self, message="Choose TestDataFile", defaultDir=os.getcwd(), 
            defaultFile=".data", wildcard=wildcard, style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR)
        #style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
        # Show the dialog and retrieve the user response. If it is the OK response, 
        # process the data.
        if dlg.ShowModal() == wx.ID_OK:
            # This returns a Python list of files that were selected.
            TestDataFileInConfigration=dlg.GetPath()
            self.TestDataFileTextCtrlInConfigration.SetValue(TestDataFileInConfigration)
            #paths = dlg.GetPaths()
        
            #self.log.WriteText('You selected %d files:' % len(paths))
        
            #for path in paths:
            #    self.log.WriteText('           %s\n' % path)
        
        # Compare this with the debug above; did we change working dirs?
        #self.log.WriteText("CWD: %s\n" % os.getcwd())
        
        # Destroy the dialog. Don't do this until you are done with it!
        # BAD things can happen otherwise!
        dlg.Destroy()
        
        if FlagDeviceInConfigration or FlagVersionInConfigration or FlagPathInConfigration  or FlagTestDataInConfigration:
            self.ReConfigButtonInConfigration.Enable()
        

    def OnStartButtonInConfigrationButton(self, event):
        self.StartButtonInConfigration.Disable()
        
        global DeviceInConfigration
        global SortTypesInConfigration
        global PathInConfigration
        global TestDataFileInConfigration
        global TestDataDir
        global VersionInConfigration
        global DeviceConfigInformation
        
        #Device=DeviceInData    
        if DeviceInConfigration =="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The DeviceNmae must not be empty In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        if PathInConfigration=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The Path must not be empty In Data!\n Maybe the format is not right!the right format is 01;02;... ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        
        elif TestDataFileInConfigration=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The LotNum must not be empty In Data!\n ','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        try:
            os.path.isfile(TestDataFileInConfigration)
        
        except OSError:
            msg="".join((r"The TestDataFile:\"",TestDataFileInConfigration,"\"isn't exist!When Using Manual Convert Data Tool."))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
        if PathInConfigration.isdigit():
            FlagDeviceConfig=False
            FlagConfirm=False
            
            ConfigPath=os.path.join(ProjectPath,"Config")
            os.chdir(ConfigPath)
            
            ConfigFileFH=open(ConfigFile,"r")
            TestItemNum,DigitalTestItemNum,TestItemName=ConfigDevice(TestDataFileInConfigration)
            DeviceConfigInformation=":".join((DeviceInConfigration,SortTypesInConfigration,VersionInConfigration,str(PathInConfigration),str(TestItemNum),DigitalTestItemNum,TestItemName))
            
            SearchPattern=":".join((DeviceInConfigration,SortTypesInConfigration,VersionInConfigration,PathInConfigration))
            for Line in ConfigFileFH.readlines() :
                if re.search(SearchPattern,Line,re.I):
                    FlagDeviceConfig=True
            ConfigFileFH.close()            
            if FlagDeviceConfig:
                    msg="".join((r"The Device:",DeviceInConfigration,"Version:",VersionInConfigration, " Configration information is exist!\n Are you Sure Continue?"))
                    dlg = wx.MessageDialog(self, msg,'A Warring Box',wx.YES_NO | wx.ICON_INFORMATION)
                    if dlg.ShowModal()==wx.ID_YES:
                        FlagConfirm=True
                    dlg.Destroy()
            if FlagConfirm: 
                if FlagDeviceConfig:
                    ConfigFileFH=open(ConfigFile,"r")
                    TempFileFH=open("mytemp","w")
                    for Line in ConfigFileFH.readlines():
                        if re.search(SearchPattern,Line,re.I):
                            TempFileFH.write("%s\n"% DeviceConfigInformation)
                        else:
                            TempFileFH.write(Line)    
                    ConfigFileFH.close()
                    TempFileFH.close()
                    del ConfigFileFH
                    del TempFileFH
                    shutil.move("mytemp",ConfigFile)
                    
                else:
                    ConfigFileFH=open(ConfigFile,"a")
                    ConfigFileFH.write("%s\n"%DeviceConfigInformation)
                    ConfigFileFH.close()
                    del ConfigFileFH
                msg="".join(("Congratulating,It's sucess!\nThe Device: ",DeviceInConfigration,"the version: ",VersionInConfigration," information has been added into config file: ",ConfigFile))
                dlg = wx.MessageDialog(self, msg,'A Ok Box',wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                    
        else:
            msg="".join((r"The Path: ",PathInConfigration,"is not digital you input. Runing Fail when you do device configuration!"))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
                    
                    

    def OnReConfigButtonInConfigrationButton(self, event):
        global DeviceInConfigration
        global VersionInConfigration
        global TestDataFileInConfigration
        global PathInConfigration
        
        self.DeviceNameTextCtrlInConfigration.SetValue("")
        DeviceInConfigration=""
        
        self.DeviceVersionTextCtrlInConfigration.SetValue("")
        VersionInConfigration=""
        
        self.TestDataFileTextCtrlInConfigration.SetValue("")
        TestDataFileInConfigration=""
        
        self.SortTypeRadioBoxInConfigration.SetSelection(0)
        SortTypesInData="Sort1"
        self.PathTextCtrlInConfigration.SetValue("")
        PathInConfigration=""
        

    def OnExitButtonInConfigrationButton(self, event):
        sys.exit()

    def OnDeviceNameChoiceInModifyPassWaferChoice(self, event):
        global DeviceInModifyPassWafer
        global FlagDeviceInModifyPassWafer
        global FlagLotNumInModifyPassWafer
        #global FlagSortType
        global FlagWaferIdInModifyPassWafer
        
        DeviceInModifyPassWafer=event.GetString()
        ConfigPath=os.path.join(ProjectPath,"Config")
        os.chdir(ConfigPath)
        
        InitiFile=open("InitSetting_Manual","r")
        self.VersionChoiceInModifyPassWafer.Clear()
        for Line in InitiFile.readlines():
            if re.search(DeviceInModifyPassWafer,Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=|,',Line)
                #TestDataDir=TempArray[1] 
                for Index in range(3,len(TempArray)):
                    self.VersionChoiceInModifyPassWafer.Append(TempArray[Index])
        
        
        if DeviceInData=="":
            FlagDeviceInModifyPassWafer=False
        else:
            FlagDeviceInModifyPassWafer=True
        
        if FlagDeviceInModifyPassWafer  and FlagLotNumInModifyPassWafer  and FlagWaferIdInModifyPassWafer:
            self.DeleteButtonInModifyPassWafer.Enable()
            self.ReConfButtonInModifyPassWafer.Enable()
            self.ExitButtonInModifyPassWafer.Enable()
        else:
            self.DeleteButtonInModifyPassWafer.Disable()
            
        print DeviceInModifyPassWafer,"FlagDeviceInModifyPassWafer:",FlagDeviceInModifyPassWafer
    def OnVersionChoiceInModifyPassWaferChoice(self,event):
        global WaferIDInModifyPassWafer
        global FlagDeviceInModifyPassWafer
        global FlagLotNumInModifyPassWafer
        #global FlagSortType
        global FlagWaferIdInModifyPassWafer
        global FlagVersionInModifyPassWafer
        global VersionInModifyPassWafer
        
        VersionInModifyPassWafer=event.GetString()
        if VersionInModifyPassWafer=="":
            FlagVersionInModifyPassWafer=False
        else:
            FlagVersionInModifyPassWafer=True
        
        if FlagDeviceInModifyPassWafer and FlagVersionInModifyPassWafer and FlagLotNumInModifyPassWafer  and FlagWaferIdInModifyPassWafer:
            self.DeleteButtonInModifyPassWafer.Enable()
            self.ReConfigButtonInModifyPassWafer.Enable()
            self.ExitButtonInModifyPassWafer.Enable()
        else:
            self.DeleteButtonInModifyPassWafer.Disable()    
        print VersionInModifyPassWafer,"FlagVersionInModifyPassWafer:",FlagVersionInModifyPassWafer

    def OnWaferIdTextCtrlInModifyPassWafer(self, event):
        global WaferIDInModifyPassWafer
        global FlagDeviceInModifyPassWafer
        global FlagLotNumInModifyPassWafer
        #global FlagSortType
        global FlagWaferIdInModifyPassWafer
        
                
        WaferIDInModifyPassWafer=""
        TempData=event.GetString()
        if TempData == "":
            dlg = wx.MessageDialog(self, 'The WaferID must not be empty In MapData!\n The format is 01;02;...','A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
                
        TempArray=re.split(r";",TempData)
        TempFlag=0
        for Temp in TempArray:
            if re.search("\D+",Temp,re.I):
                if not re.search("~",Temp,re.I):
                    TempFlag=1
                    continue
            elif len(Temp)>0:
                if int(Temp)>25:
                    TempFlag=2
            else:
                TempArray.remove(Temp)
                if TempFlag==1:
                    dlg = wx.MessageDialog(self, 'There is some no digital in WaferID string In Data! ','A Error Box',wx.OK | wx.ICON_INFORMATION)
                    dlg.ShowModal()
                    dlg.Destroy()
                elif TempFlag==2:
                    dlg = wx.MessageDialog(self, 'There is some wrong waferID(That is more than 25 In Data!','A Error Box',wx.OK | wx.ICON_INFORMATION)
                    dlg.ShowModal()
                    dlg.Destroy() 
                WaferIDInModifyPassWafer=TempArray
                if len(WaferIDInModifyPassWafer)<1:
                    FlagWaferIdInModifyPassWafer=False
                else:
                    FlagWaferIdInModifyPassWafer=True
                if FlagDeviceInModifyPassWafer and FlagLotNumInModifyPassWafer  and FlagWaferIdInModifyPassWafer:
                    self.DeleteButtonInModifyPassWafer.Enable()
                    self.ReConfButtonInModifyPassWafer.Enable()
                    self.ExitButtonInModifyPassWafer.Enable()
                else:
                    self.DeleteButtonInModifyPassWafer.Disable()
                            
                print WaferIDInModifyPassWafer,"FlagWaferIdInModifyPassWafer:",FlagWaferIdInModifyPassWafer
        

    def OnSortTypesRadioBoxInModifyPassWaferRadiobox(self, event):
        global SortTypesInModifyPassWafer
        SortTypeSelect=event.GetInt()
        if SortTypeSelect==0:
            SortTypesInModifyPassWafer="Sort1"
        elif SortTypeSelect==1:
            SortTypesInModifyPassWafer="Sort2"  
        #print SortTypesInModifyPassWafer
        

    def OnLotNoTextCtrlInModifyPassWaferText(self, event):
        global LotNumInModifyPassWafer
        global FlagDeviceInModifyPassWafer
        global FlagLotNumInModifyPassWafer
        #global FlagSortType
        global FlagWaferIdInModifyPassWafer
        
        
        LotNumInModifyPassWafer =event.GetString()
        if LotNumInModifyPassWafer=="":
            FlagLotNumInModifyPassWafer=False
        else:
            FlagLotNumInModifyPassWafer=True
        
        if FlagDeviceInModifyPassWafer and FlagLotNumInModifyPassWafer  and FlagWaferIdInModifyPassWafer:
            self.DeleteButtonInModifyPassWafer.Enable()
            self.ReConfButtonInModifyPassWafer.Enable()
            self.ExitButtonInModifyPassWafer.Enable()
        else:
            self.DeleteButtonInModifyPassWafer.Disable()   
        print LotNumInModifyPassWafer,"FlagLotNumInModifyPassWafer:",FlagLotNumInModifyPassWafer
        

    def OnLotNoButtonInModifyPassWaferButton(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)
        
        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global LotNumInModifyPassWafer
            #TempArray=re.split(r"\\",dlg.GetPath())
            #LotNumInData=TempArray[len(TempArray)-1]
            LotNumInModifyPassWafer=os.path.basename(dlg.GetPath())
            self.LotNoTextCtrlInModifyPassWafer.SetValue(LotNumInModifyPassWafer)
            #print LotNumInData 
            #print len(TempArray)
        
        # Only destroy a dialog after you're done with it.
        dlg.Destroy()
        

    def OnDeleteButtonInModifyPassWaferButton(self, event):
        self.StartButtonInConfigration.Disable()
        
        global DeviceInModifyPassWafer
        global LotNumInModifyPassWafer
        global SortTypesInModifyPassWafer
        global WaferIDInModifyPassWafer
        global VersionInModifyPassWafer
        global TestDataDir
        
        LogPath=os.path.join(ProjectPath,"Log")
        os.chdir(LogPath)
        
        WaferIds=[]
        #TempArray=re.split(";",WaferIDInModifyPassWafer,re.I)
        for Temp in WaferIDInModifyPassWafer:
            if re.search("~",Temp,re.I):
                MyTemp=re.split("~",Temp,re.I)
                Min,Max=min(int(MyTemp[0]),int(MyTemp[1])),max(int(MyTemp[0]),int(MyTemp[1]))
                for Num in range(int(Min),int(Max)+1):
                    if not str(Num) in WaferIds:
                        WaferIds.append(str(Num))
            elif Temp.isdigit():
                WaferIds.append(Temp) 
        PassWaferLogFileFH=open("passwafer.log","r")
        TempLogFileFH=open("templogfile","w")
        
        
        while True:
            Line = PassWaferLogFileFH.readline()
            if len(Line)==0:
                break
            FlagPassWaferExist=False
            for WaferId in WaferIds :                
                TempLotWaferId=""
                if int(WaferId) <10:
                    TempLotWaferId=LotNumInModifyPassWafer+"-0"+str(int(WaferId))
                else:
                    TempLotWaferId=LotNumInModifyPassWafer+"-"+str(WaferId)
                if re.search(DeviceInModifyPassWafer,Line,re.I) and re.search(TempLotWaferId,Line,re.I)and re.search(SortTypesInModifyPassWafer,Line,re.I):
                    FlagPassWaferExist=True
            if not FlagPassWaferExist:    
                TempLogFileFH.write(Line)
        
        PassWaferLogFileFH.close()
        TempLogFileFH.close()
        del PassWaferLogFileFH
        del TempLogFileFH
        
        shutil.move("templogfile","passwafer.log")  
        
        #####################################################
        #Unzip Data file if First Data files have been zipped
        #####################################################
        DeviceVersion="".join((DeviceInModifyPassWafer,"_",VersionInModifyPassWafer))
        LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInModifyPassWafer)
        DataPath=os.path.join(LotPath,"Data") 
        
        os.chdir(DataPath)
        ZipFileName="".join((DeviceInModifyPassWafer,"_",VersionInModifyPassWafer,"_",LotNumInModifyPassWafer,"_",SortTypesInModifyPassWafer,"_","data.zip"))
        if os.path.isfile(ZipFileName):                 
            FileName=zipfile.ZipFile(ZipFileName,"r")
            for TempFile in FileName.namelist():
                TempArrayDatas=re.split("_",TempFile)
                Temp=re.split("-",TempArrayDatas[4])
                for WaferId in WaferIds:
                    if (re.search(LotNumInModifyPassWafer,TempFile,re.I))and (int(WaferId) ==int(Temp[1]))and (string.upper(SortTypesInModifyPassWafer) == string.upper(TempArrayDatas[3])) :                   
                        WaferFile=TempFile
                        WaferFileFH=open(WaferFile,"w")
                        WaferFileFH.write(FileName.read(WaferFile))
                        WaferFileFH.close()
            FileName.close()
        

    def OnReConfButtonInModifyPassWaferButton(self, event):
        self.DeviceNameChoiceInModifyPassWafer.Clear()
        DeviceInModifyPassWafer=""
        
        self.LotNoTextCtrlInModifyPassWafer.Clear()
        LotNumInModifyPassWafer=""
        
        self.WaferIdTextCtrlInModifyPassWafer.Clear()
        WaferIDInModifyPassWafer=""
        
        self.SortTypeRadioBoxInConfigration.SetSelection(0)
        SortTypesInModifyPassWafer="Sort1"

    def OnExitButtonInModifyPassWaferButton(self, event):
        sys.exit()

    def OnDeviceChoiceInConfirmPassLotChoice(self, event):
                
        global DeviceInConfirmPassLot
        global FlagDeviceInConfirmPassLot
        global FlagLotNumInConfirmPassLot
        global FlagRespInConfirmPassLot
        global FlagVersionInConfirmPassLot
        
        DeviceInConfirmPassLot=event.GetString()
        ConfigPath=os.path.join(ProjectPath,"Config")
        os.chdir(ConfigPath)
        
        InitiFile=open("InitSetting_Manual","r")
        self.VersionChoiceInConfirmPassLot.Clear()
        for Line in InitiFile.readlines():
            if re.search(DeviceInConfirmPassLot,Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=|,',Line)
                #TestDataDir=TempArray[1] 
                for Index in range(3,len(TempArray)):
                    self.VersionChoiceInConfirmPassLot.Append(TempArray[Index])
                    
        #    elif re.search(r'Device=',Line,re.I):
        #        Line=Line.strip()
        #        TempArray=re.split(r'=|,',Line)
        #        DeviceInData.append(TempArray[1])
        #        VersionInData[TempArray[1]]=TempArray[3]
        #self.DeviceChoiceInData.SetValue(DeviceInData)        
        InitiFile.close      
        if DeviceInConfirmPassLot=="":
            FlagDeviceInConfirmPassLot=False
        else:
            FlagDeviceInConfirmPassLot=True
        
        if FlagDeviceInConfirmPassLot and FlagVersionInConfirmPassLot and FlagLotNumInConfirmPassLot and FlagRespInConfirmPassLot:
            self.StartButtonInConfirmPassLot.Enable()
            self.ReConfigButtonInConfirmPassLot.Enable()
            self.ExitButtonInConfirmPassLot.Enable()
        else:
            self.StartButtonInConfirmPassLot.Disable()
            
        print DeviceInConfirmPassLot,"FlagDeviceInConfirmPassLot:",FlagDeviceInConfirmPassLot
    
    def OnVersionChoiceInConfirmPassLotChoice(self,event):
        global VersionInConfirmPassLot
        global FlagDeviceInConfirmPassLot
        global FlagLotNumInConfirmPassLot
        global FlagRespInConfirmPassLot
        global FlagVersionInConfirmPassLot
        
        VersionInConfirmPassLot=event.GetString()
        if VersionInConfirmPassLot=="":
            FlagVersionInConfirmPassLot=False
        else:
            FlagVersionInConfirmPassLot=True
        
        if FlagDeviceInConfirmPassLot and FlagVersionInConfirmPassLot and FlagLotNumInConfirmPassLot  and FlagRespInConfirmPassLot:
            self.StartButtonInConfirmPassLot.Enable()
            self.ReConfigButtonInConfirmPassLot.Enable()
            self.ExitButtonInConfirmPassLot.Enable()
        else:
            self.StartButtonInConfirmPassLot.Disable()    
        print VersionInConfirmPassLot,"FlagVersionInConfirmPassLot:",FlagVersionInConfirmPassLot


    def OnLotNoTextCtrlInConfirmPassLotText(self, event):
        global LotNumInConfirmPassLot
        global FlagDeviceInConfirmPassLot
        global FlagLotNumInConfirmPassLot
        global FlagRespInConfirmPassLot
        global FlagVersionInConfirmPassLot
        
        LotNumInConfirmPassLot =event.GetString()
        if LotNumInConfirmPassLot=="":
            FlagLotNumInConfirmPassLot=False
        else:
            FlagLotNumInConfirmPassLot=True
        
        if FlagDeviceInConfirmPassLot and FlagVersionInConfirmPassLot and FlagLotNumInConfirmPassLot  and FlagRespInConfirmPassLot:
            self.StartButtonInConfirmPassLot.Enable()
            self.ReConfButtonInConfirmPassLot.Enable()
            self.ExitButtonInConfirmPassLot.Enable()
        else:
            self.StartButtonInConfirmPassLot.Disable()   
        print LotNumInConfirmPassLot,"FlagLotNumInConfirmPassLot:",FlagLotNumInConfirmPassLot


    def OnLotNoButtonInConfirmPassLotButton(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)
        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global LotNumInConfirmPassLot
            #TempArray=re.split(r"\\",dlg.GetPath())
            #LotNumInData=TempArray[len(TempArray)-1]
            LotNumInConfirmPassLot=os.path.basename(dlg.GetPath())
            self.LotNoTextCtrlInConfirmPassLot.SetValue(LotNumInConfirmPassLot)
            #print LotNumInData 
            #print len(TempArray)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()

    def OnRespChoiceInConfirmPassLotChoice(self, event):
        global RespInConfirmPassLot
        global FlagDeviceInConfirmPassLot
        global FlagLotNumInConfirmPassLot
        global FlagRespInConfirmPassLot
        global FlagVersionInConfirmPassLot
        
        RespInConfirmPassLot=event.GetString()
        if RespInConfirmPassLot=="":
            FlagRespInConfirmPassLot=False
        else:
            FlagRespInConfirmPassLot=True
        
        if FlagDeviceInConfirmPassLot and FlagVersionInConfirmPassLot and FlagLotNumInConfirmPassLot  and FlagRespInConfirmPassLot:
            self.StartButtonInConfirmPassLot.Enable()
            self.ReConfButtonInConfirmPassLot.Enable()
            self.ExitButtonInConfirmPassLot.Enable()
        else:
            self.StartButtonInConfirmPassLot.Disable()    
        print RespInConfirmPassLot,"FlagRespInConfirmPassLot:",FlagRespInConfirmPassLot

    def OnStartButtonInConfirmPassLotButton(self, event):
        self.StartButtonInConfirmPassLot.Disable()
        self.ReConfButtonInConfirmPassLot.Disable()
        self.ExitButtonInConfirmPassLot.Disable()
        global DeviceInConfirmPassLot
        global LotNumInConfirmPassLot
        global VersionInConfirmPassLot
        global RespInConfirmPassLot
        global TestDataDir
        global ProjectPath
        
        DeviceVersion="".join((DeviceInConfirmPassLot,"_",VersionInConfirmPassLot))  
        DevicePath=os.path.join(TestDataDir,DeviceVersion)
        LotPath=os.path.join(DevicePath,LotNumInConfirmPassLot)     
        FlagConfirm = False
        
        if os.path.isdir(LotPath):
            BHTCPath=os.path.join(LotPath,"Bhtc")
            if os.path.isdir(BHTCPath):
                os.chdir(BHTCPath)
                BHTCSort1FileNum=0
                BHTCSort2FileNum=0
                BHTCFiles=glob.glob('*.bhtc')
                for TempFile in BHTCFiles:
                    if re.search(r'Sort1',TempFile,re.I):
                        BHTCSort1FileNum+=1
                    elif re.search(r'Sort2',TempFile,re.I):
                        BHTCSort2FileNum+=1
                if (BHTCSort1FileNum==25)  and (BHTCSort2FileNum==25) :
                    FlagConfirm=True
                    
                elif (BHTCSort1FileNum < BHTCSort2FileNum):
                    msg="".join((r'The Sort1 File Count is less then Sort2 !Please Check it!\n Action Fail!'))
                    dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
                    dlg.ShowModal()
                    dlg.Destroy()
                elif (BHTCSort1FileNum > BHTCSort2FileNum):
                    msg="".join((r'The Sort2 File Count is less then Sort1 !\nAre you Sure the Test complete!Please Check it!\n Action Fail!'))
                    dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
                    dlg.ShowModal()
                    dlg.Destroy()   
                elif ( BHTCSort1FileNum <25) and (BHTCSort1FileNum == BHTCSort2FileNum) :
                    msg="".join((r'The Test Data File is less than 25!\n Are you sure Continue?'))
                    dlg = wx.MessageDialog(self, msg,'A Warring Box',wx.YES_NO | wx.ICON_INFORMATION)
                    if dlg.ShowModal()==wx.ID_YES:
                        FlagConfirm=True
                    dlg.Destroy()   
                    
            else:
                msg="".join((r'The BHTC Directory is not exist!\n Action Fail!'))
                dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
        else:     
            msg="".join((r'The Lot: ', LotNumInConfirmPassLot,r'Directory is not exist!\n Action Fail!'))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
                
        if FlagConfirm:
            os.chdir(DevicePath)
            TarFileName="".join((LotNumInConfirmPassLot,".tar.gz"))
            TarLotFile=tarfile.TarFile.open(TarFileName,'w:gz')
            AllTargets=glob.glob(LotNumInConfirmPassLot)
            for Temp in AllTargets:
                TarLotFile.add(Temp)
            TarLotFile.close()
            
            LogPath=os.path.join(ProjectPath,"Log")         
            TimeConfirm=time.asctime()
            PassLotLogFile=os.path.join(LogPath,"passlot.log")
            PassLotLogFileFH=open(PassLotLogFile,"a")
            PassLotLogFileFH.write("%27s%s%19s%s%23s%s%20s\n" % (TimeConfirm,r"|",DeviceInConfirmPassLot,r"|",LotNumInConfirmPassLot,r"|",RespInConfirmPassLot))
            PassLotLogFileFH.close()
            self.MyDelDir(LotPath,False)
        self.StartButtonInConfirmPassLot.Enable()
        self.ReConfButtonInConfirmPassLot.Enable()
        self.ExitButtonInConfirmPassLot.Enable()
        

    def OnReConfButtonInConfirmPassLotButton(self, event):
        global DeviceInConfirmPassLot
        global VersionInConfirmPassLot
        global LotNumInConfirmPassLot
        global RespInConfirmPassLot
                
        self.DeviceChoiceInConfirmPassLot.SetSelection(-1)
        DeviceInConfirmPassLot=""
                
        self.VersionChoiceInConfirmPassLot.SetSelection(-1)
        VersionInConfirmPassLot=""
                
        self.LotNoTextCtrlInConfirmPassLot.SetValue("")     
        LotNumInConfirmPassLot=""
                
        self.RespChoiceInConfirmPassLot.SetSelection(-1)
        RespInConfirmPassLot=""
        

    def OnExitButtonInConfirmPassLotButton(self, event):
        sys.exit()
    def MyDelDir(self,MyDir,Flag):
        for root,dirs,files in os.walk(MyDir,Flag):
            for name in files:
                os.remove(os.path.join(root,name))
            for name in dirs:
                os.rmdir(os.path.join(root,name))
        os.chdir(os.path.dirname(MyDir))
        os.rmdir(MyDir)
    def OnOpenButton(self,event):
        dlg = wx.FileDialog(self, wildcard="*.pdf")

        if dlg.ShowModal() == wx.ID_OK:
            wx.BeginBusyCursor()
            self.pdf.LoadFile(dlg.GetPath())
            wx.EndBusyCursor()

        dlg.Destroy()                  

    def OnOpenHelpFileButtonInConfigrationButton(self, event):
        global ProjectPath
        global HelpFile
        
        ConfigPath=os.path.join(ProjectPath,"Config")        
        
        if os.path.isfile(os.path.join(ConfigPath,HelpFile)):
            os.startfile(os.path.join(ConfigPath,HelpFile))
                          
                                    
                                
        

   
